dart-async

is there any way to cancel a dart Future?

戏子无情 提交于 2019-11-27 08:30:34
In a Dart UI, I have a button [submit] to launch a long async request. The [submit] handler returns a Future. Next, the button [submit] is replaced by a button [cancel] to allow the cancellation of the whole operation. In the [cancel] handler, I would like to cancel the long operation. How can I cancel the Future returned by the submit handler? I found no method to do that. As far as I know, there isn't a way to cancel a Future. But there is a way to cancel a Stream subscription, and maybe that can help you. Calling onSubmit on a button returns a StreamSubscription object. You can explicitly

How to get the full stack trace for async execution

一世执手 提交于 2019-11-27 06:16:42
问题 For a small example like import 'dart:async'; import 'package:stack_trace/stack_trace.dart'; void main() { scheduleAsync(); } void scheduleAsync() { new Future.delayed(new Duration(seconds: 1)) .then((_) => runAsync()); } void runAsync() { throw 'oh no!'; } I get this stack trace. The furthest I can trace the call back is the runAsync() call in scheduleAsync() . There is no information left, that scheduleAsync was called from main . Unhandled exception: Uncaught Error: oh no! Stack Trace: #0

How can I merge multiple Streams into a higher level Stream?

拟墨画扇 提交于 2019-11-27 05:53:07
问题 I have two streams, Stream<A> and Stream<B> . I have a constructor for a type C that takes an A and a B . How do I merge the two Stream s into a Stream<C> ? 回答1: You can use StreamZip in package:async to combine two streams into one stream of pairs, then create the C objects from that. import "package:async" show StreamZip; ... Stream<C> createCs(Stream<A> as, Stream<B> bs) => new StreamZip([as, bs]).map((ab) => new C(ab[0], ab[1])); 回答2: import 'dart:async' show Stream; import 'package:async