new Observable.race([
new Observable.timer(1, new Duration(days: 1)),
new Observable.timer(2, new Duration(days: 2)),
new Observable.timer(3, new Duration(seconds: 1))
]).listen(print); // prints 3
import 'package:async/async.dart';
Stream<MobileAdEvent> adEventStream;
Stream<Color> colorStream;
final merged = StreamGroup.merge([
_orderStream.stream,
_orderStream.stream.map((event) => event.hashCode),
]);
final subscription = merged.listen((event) {
if (event is MobileAdEvent) {
// handle event from first stream
}
if (event is Color) {
// handle event from second stream
}
});
3条答案
按热度按时间42fyovps1#
您需要的是
combineLatest
运算符wtzytmuj2#
你试过
Observable.race
吗?它非常适合通知:给定两个或多个源流,仅从其中的第一个流发出所有项,以发出项或通知。
了解更多https://pub.dev/documentation/rxdart/latest/rx/Observable/Observable.race.html
zsohkypk3#
使用StreamGroup.merge并检查对象类型: