Created
March 9, 2020 06:39
-
-
Save AlexKenbo/7376d0d7e5a1440116233cd235173631 to your computer and use it in GitHub Desktop.
Stream - .addStream(), pipe()
This file contains hidden or 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'; | |
var stream = Stream.fromIterable([1, 2, 3, 4, 5]); | |
void main() { | |
final controller1 = new StreamController(); | |
final controller2 = new StreamController(); | |
controller1.addStream(stream); | |
final doubler = | |
new StreamTransformer.fromHandlers(handleData: (data, sink) { | |
sink.add(data * 2); | |
}); | |
controller1.stream.transform(doubler).pipe(controller2); | |
controller2.stream.listen((data) => print(data)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment