Skip to content
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

Stream.takeUntil (or something) #8082

Closed
blois opened this issue Jan 23, 2013 · 5 comments
Closed

Stream.takeUntil (or something) #8082

blois opened this issue Jan 23, 2013 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant core-n P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@blois
Copy link
Contributor

blois commented Jan 23, 2013

I'm looking for something similar to takeWhile, but rather than performing the check before accepting the data, it performs the check after accepting the data.

I'm hitting this converting dart:html tests over to streams, in a number of the tests. The scenario is that they are listening to postMessage events until getting the one that they're looking for, then want to unsubscribe.

Alternatives are:
var complete = false;
window.onMessage.takeWhile((_) => !complete).listen((e) {
  if (e.data == 'hello') {
    complete = true;
  }
});

Which is ugly because it requires an extra event to unsubscribe and will get any errors before that event.

And:
var subscription = null;
subscription = window.onMessage.listen((e) {
  if (e.data == 'hello') {
    subscription.cancel();
  }
});
Which works, though the declaration of subscription is sort of ugly.

@blois
Copy link
Contributor Author

blois commented Feb 11, 2013

I'm hitting this using streams for Indexed DB cursors as well. I want to iterate through items until I find a particular item.


cc @floitschG.

@floitschG
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement label.

@floitschG
Copy link
Contributor

cc @lrhn.

@lrhn
Copy link
Member

lrhn commented Feb 11, 2013

Am I understanding correctly that you want exactly one event that matches some test?
If so, Stream.firstMatching seems like the perfect match. If you don't want the errors on the stream, discard them first:
  Future mathcedEvent = stream.catchError((_){}).firstMatching(test);

@blois
Copy link
Contributor Author

blois commented Feb 11, 2013

In some cases the data is being processed along the way.

firstMatching probably works for this though- just ignore the result and do
the processing the the matching test. It's a bit more concise than
takeUntil as well.

@blois blois added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Feb 11, 2013
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@lrhn lrhn added the core-m label Aug 11, 2017
@floitschG floitschG added core-n and removed core-m labels Aug 29, 2017
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant core-n P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants