Skip to content

Instantly share code, notes, and snippets.

@alexcmgit
Last active December 7, 2022 18:53
Show Gist options
  • Save alexcmgit/17e2720be36c2bbde3da7d5a6381776d to your computer and use it in GitHub Desktop.
Save alexcmgit/17e2720be36c2bbde3da7d5a6381776d to your computer and use it in GitHub Desktop.
void main() {
// Simulate the [signinResponse] as a simply [String].
Stream<String> signInStream() => Stream<String>.periodic(Duration(seconds: 1), (computation) => 'Login $computation');
// Simulate the [userResponse] as a simply [int].
Stream<int> getUserDetailsStream() => Stream<int>.periodic(Duration(seconds: 1));
final Stream<Stream<int>> itIsWhatYouAreDoing = signInStream().asyncMap((event) => getUserDetailsStream());
// What you are saying you want to achieve:
final Stream<int> userDetailsStream = signInStream().asyncMap((event) async => await getUserDetailsStream().first);
print(itIsWhatYouAreDoing); // Stream<Stream<int>>
print(userDetailsStream); // Stream<int>
// But this has some cons: you lose any other post-event emitted by all [getUserDetailsStream] Streams.
// You didn't provide any detail about this, so I'll assuming they are irrelevant?!?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment