is there any way to cancel a dart Future?

后端 未结 9 1511
礼貌的吻别
礼貌的吻别 2020-11-27 05:55

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 a

9条回答
  •  长情又很酷
    2020-11-27 05:58

    Change the future's task from 'do something' to 'do something unless it has been cancelled'. An obvious way to implement this would be to set a boolean flag and check it in the future's closure before embarking on processing, and perhaps at several points during the processing.

    Also, this seems to be a bit of a hack, but setting the future's timeout to zero would appear to effectively cancel the future.

提交回复
热议问题