Created
January 21, 2021 07:47
-
-
Save ctalladen78/e6150f787b351924d7e5b17bf530e07d to your computer and use it in GitHub Desktop.
RXDart PublishSubject example
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'; | |
import 'package:rxdart/rxdart.dart'; | |
void main() { | |
var streamCtrl = PublishSubject<String>(); | |
streamCtrl.stream.listen(observer1); | |
streamCtrl.stream.listen(observer2); | |
action(streamCtrl.sink); | |
} | |
void action(Sink<String> sink){ | |
sink.add("hello streams"); | |
} | |
void observer1(String data) async { | |
print("observer 1 response: $data"); | |
} | |
void observer2(String data) async { | |
print("observer 2 response: $data"); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment