Last active
March 2, 2020 14:33
-
-
Save ragnor-rs/b33fbda8da6724f4e203928ce2233ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
final streamController = StreamController<int>(); | |
Future<void> process(int event) async { | |
print("Processing $event..."); | |
} | |
Stream<String> mapEventToState(int event) async* { | |
yield "Loading $event..."; | |
await process(event); | |
yield "Loaded $event"; | |
if (event == 0) { | |
send(4); | |
} | |
} | |
void send(int event) { | |
streamController.add(event); | |
print("Sent $event"); | |
} | |
void main() { | |
streamController.stream.asyncExpand((event) => mapEventToState(event)).listen((state) => print("State: $state")); | |
for (int i = 0; i < 3; i++) { | |
send(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment