Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

Dart add new Stream to stream group

I want to make several periodic REST API calls and merge all the responses into one single stream. This is possible with StreamGroup, but is it possible to merge a new stream to the already existing stream at runtime? Let's say I have two periodic streams that I merge into one stream with StreamGroup. How can I add/merge a new stream.periodic (for example getC()) to the already existing Stream stream after it was created (so after StreamGroup.merge(streamList)) ?


import 'package:async/async.dart' show StreamGroup;

// ... 
Stream<dynamic> stream;
var streamList = <Stream>[];

// ...

void addPeriodicCallToA({Duration period}) {
    streamList.add(Stream<dynamic>.periodic(period, (x) async {
      return await getA();
    }));
  }

// ...

void addPeriodicCallToB({String symbol, Duration period}) {
    streamList.add(Stream<dynamic>.periodic(period, (x) async {
      return await getB(symbol: symbol);
    }));
  }

// ...

addPeriodicCallToA(period: Duration(seconds: 1));
addPeriodicCallToA(period: Duration(symbol: 'yoloandswaglol', seconds: 2));
stream = StreamGroup.merge(streamList);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...