第18章非同期プログラミング-stream_length

反収集マーク:カン・シャオジュン先生のコースと資料

//stream_length.dart文件
import 'dart:async';

void main(){
  //创建Stream,并统计事件的总数量
  testStreamLength();
}

void testStreamLength() async {
  //时间间隔为1秒
  Duration interval = Duration(seconds: 1);
  //每隔1秒发送1次的事件流
  Stream
  
    stream = Stream.periodic(interval, (data) => data);
  stream = stream.take(5);
  //统计事件的总数量
  var allEvents = await stream.length;
  print(allEvents);
}
  
  • ダーツ交換グループ:1046954554
  • Flutterオープンソースプロジェクトに注意してください:https//github.com/kangshaojun

@作者:カン・シャオジュン

'

おすすめ

転載: blog.csdn.net/kangshaojun888/article/details/104542190