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.pipe should return a Future<void> #44510

Open
srawlins opened this issue Dec 18, 2020 · 3 comments
Open

Stream.pipe should return a Future<void> #44510

srawlins opened this issue Dec 18, 2020 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async

Comments

@srawlins
Copy link
Member

The implementation for Stream.pipe is:

Future pipe(StreamConsumer<T> streamConsumer) {
  return streamConsumer.addStream(this).then((_) => streamConsumer.close());
}

Shouldn't this method return Future<void> rather than Future<dynamic>? My motivation is for #35825, where I'm catching code like:

myStream
  .pipe(something)
  .catchError((e) => print(e));

So Future<dynamic>.catchError's onError handler should return FutureOr<dynamic>, and returning void from the handler would be an error.

@srawlins srawlins added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async labels Dec 18, 2020
@lrhn
Copy link
Member

lrhn commented Dec 18, 2020

Yes, it should.
I guess it's technically a breaking change if anyone uses the result, but nobody should be using it.

@SteveAlexander
Copy link

The docs for pipe say "The returned future completes with the same result as the future returned by [StreamConsumer.close]. If the call to [StreamConsumer.addStream] fails in some way, this method fails in the same way."

This makes sense, because StreamConsumer.close says the return value is used for error reporting:
"Returns a future which is completed when the consumer has shut down. If cleaning up can fail, the error may be reported in the returned future, otherwise it completes with null."

I guess StreamConsumer<S> could be changed to StreamConsumer<S, E>, with a new generic type for the return type of close. But I don't think I've seen this feature of close used before.

@Baksman
Copy link

Baksman commented May 27, 2022

In case anyone is having such issue image

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. library-async
Projects
None yet
Development

No branches or pull requests

4 participants