Skip to content

Instantly share code, notes, and snippets.

@kuronekomichael
Created September 15, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuronekomichael/dfeb0bd5f572cfcfdcc397a3e1cf67b9 to your computer and use it in GitHub Desktop.
Save kuronekomichael/dfeb0bd5f572cfcfdcc397a3e1cf67b9 to your computer and use it in GitHub Desktop.
import 'package:rxdart/rxdart.dart';
import 'package:test/test.dart';
void main() {
test('BehaviorSubjectのサンプル', () {
BehaviorSubject<int> subject = new BehaviorSubject<int>();
// 1, 2をStreamに流す。しかしこの時点ではListenerがいないので配信されない
subject.sink.add(1);
subject.sink.add(2);
// 1, 2は流れてしまった後に、Listenerを追加。最後の要素の2を受け取ることができる
subject.listen(expectAsync1((int data) {
expect(data, 2);
}));
// さらに別のListenerも追加。Broadcastなので、こちらでも受信できる
subject.listen(expectAsync1((int data) {
expect(data, 2);
}));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment