在飞镖中执行节流功能

问题描述 投票:5回答:1

Dart中有没有办法像这样限制函数执行

Observable.throttle(myFunction,2000);

dart flutter throttling rxdart
1个回答
1
投票

使用https://pub.dartlang.org/documentation/rxdart/latest/rx/Observable/throttle.html

所以,你在Dart 2中使用RxDart的例子是

final subject = new ReplaySubject<int>();
myCaller(Event event) {
  subject.add(event);
}
subject
  .throttle(Duration(seconds: 2))
  .listen(myHandler);
© www.soinside.com 2019 - 2024. All rights reserved.