-
Notifications
You must be signed in to change notification settings - Fork 3
What consistency properties would we like to guarantee when calling .next
concurrently?
#3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Does this mean that the first promise (from the first call to I would prefer the second: that the values should be yielded in the same structural sequence, but not necessarily in the same temporal sequence. Of course, for everything but |
As written I don't mean for it to imply that it needs to settle first, just that it needs to settle with the first value. But I think it's a consequence that it needs to settle first, at least for helpers, at least on the assumption that we maintain the property of existing async iterators in the language that you get (Also if you're preserving order of values it's fundamentally impossible to settle later promises before earlier ones for
Sure, that's true depending on your definitions of "pure", but I intend for it to count as pure for the purposes of this consistency property. Essentially I mean to talk about purity in a world where we model exceptions by saying that all functions are actually returning a |
Revisiting this, I think the consistency property mentioned above may be too strong. In particular, the fact that it forces returned promises to settle in order (at least those prior to the first A potential weakening of the property which recovers the ability to write |
I think we should guarantee you get the same results in the same order as if you had made the calls sequentially (assuming no funny business in the mapper/iterator).
To be more precise:
Say that an iterator is race-free if it gives the same results in the same order regardless of whether calls to its
.next
method happen sequentially or concurrently.Note that this is a very weak property: an iterator can do stuff like returning
[{ done: true }, { done: false }]
and still be race-free.The fundamental consistency property of iterator helpers is that as long as the underlying iterator is race-free and the mapping function is pure, the resulting iterator is race-free. (In the case of
flatMap
, which has multiple underlying iterators, they all need to be race-free, and also to share no state, in order for this guarantee to hold.)This immediately implies that promises have to settle in order. For example, consider an async mapping function which
{ done: true }
(or, equivalently, throws).{ done: false, value: 0 }
.Consider
it = underlying.map(thatFunction); first = it.next(); second = it.next()
. Even though a result forsecond
is available immediately, if you had put asleep(60_000)
before thesecond =
, you would have seen{ done: true }
forsecond
. So that's what you need to see in this code as well to be race-free.That is, there's no way you can get the right answer for
second
without seeing howfirst
resolves, because the result offirst
might indicate the end of iteration.[edit: actually, a promise for
{ done: true }
can settle immediately without violating the consistency property, because once you see that you know all future values will be{ done: true }
.]The text was updated successfully, but these errors were encountered: