-
Notifications
You must be signed in to change notification settings - Fork 33
should AsyncIterator.protoype.filter have a fast path for sync predicates? #230
Comments
Why only |
Given the choices:
I would choose always await, it seems to be the least chaotic. |
@devsnek |
@zloirock yes i agree. |
@zloirock Yes we could support other primitives, but it gets more murky. What would the algorithm be? If it's an object, assume it's thenable, otherwise ToBoolean it? It would prevent weird things like putting a |
The algorithm would be if Type is Object, go the slow path. Seems reasonable to me. |
If we allow other primitives it's likely to run into weird timing issues. It's easy to image a predicate function which returns either an object or On the other hand, maybe "number of ticks" is a thing not really worth caring about? |
Only in that the desire is to minimize them in a predictable way, which i think “returns an object or null” achieves. |
I think in these cases the more important thing is consistent behavior. this await will not be the "slow" part of real world code, the I/O from whatever async api is driving it will be. |
|
Because those need to be run in serial; filter operations do not. |
Nope. All methods from this proposal should be run in serial, |
What i mean is, conceptually, forEach is for side effects - filter is supposed to be pure. Obviously they all need to run in order, but failing to await forEach would cause bugs in otherwise reasonable code - filter would not. |
It's not obvious to me how failing to await |
...and the same situation with callbacks of almost all methods from this proposal - |
Putting a |
@bakkot actually yeah, good point. that suggests they can all have this fast path. |
I will point out that having a fast path is dangerously close to "releasing Zalgo". My original question was more to whether the result returned from the callback to |
@rbuckton Ah, I didn't know about that test. That makes calling |
@rbuckton all methods of async iterators from this proposal that accept a callback accept async functions, I don't see any reason to make an exception only for |
Also, to my point about "releasing Zalgo", there is still an |
As mentioned by @rbuckton in #117 (comment).
Also it was questioned whether
true
/false
should be the fast path or truthy/falsey non-thenables. I would only supporttrue
/false
.The text was updated successfully, but these errors were encountered: