You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the same way that programming with Futures could benefit from language support (issue #104), programming with Streams could as well. Streams are essentially async Iterables, so an async version of the "for" statement could work for Streams. It probably makes sense to call it "on" which is already a contextual keyword elsewhere. As an example the implementation of the Iterable-based methods on Stream could look identical to how they are in Iterable except replacing "on" with "for":
async bool any(bool f(E e)) {
on(var e in this) {
if(f(e)) return true;
}
return false;
}
notes:
* the "on" statement would trigger a "subscribe" to the Stream passing onData, onDone, and onError resulting in a StreamSubscription
as with await, the enclosing function would implicitly return a Future
as with await, errors within the construct would throw the unwrapped error, not the AsyncError wrapper
any "break" or "return" in the "on" statement would trigger an "unsubscribe" on the StreamSubscription
nested "await"s and "on"s could be delimited by "pause()" and "resume()" on the StreamSubscription, and since that's only a best effort, any events which occur before the nested items complete could be buffered for use in later iterations of the "on" statement.
The Dart spec now includes async* methods and await for loops. Not fully implemented yet, but in progress. I'm closing this bug as "Done" from the language perspective.
This issue was originally filed by @seaneagan
In the same way that programming with Futures could benefit from language support (issue #104), programming with Streams could as well. Streams are essentially async Iterables, so an async version of the "for" statement could work for Streams. It probably makes sense to call it "on" which is already a contextual keyword elsewhere. As an example the implementation of the Iterable-based methods on Stream could look identical to how they are in Iterable except replacing "on" with "for":
async bool any(bool f(E e)) {
on(var e in this) {
if(f(e)) return true;
}
return false;
}
notes:
* the "on" statement would trigger a "subscribe" to the Stream passing onData, onDone, and onError resulting in a StreamSubscription
Initial mailing list discussion:
http://goo.gl/8PqcP
The text was updated successfully, but these errors were encountered: