> On Aug 17, 2017, at 11:53 PM, Jan Tuitman via swift-evolution > <swift-evolution@swift.org> wrote: > > Hi, > > > After reading Chris Lattners proposal for async/await I wonder if the > proposal has any way to cancel outstanding tasks. > > I saw these two: > > @IBAction func buttonDidClick(sender:AnyObject) { > // 1 > beginAsync { > // 2 > let image = await processImage() > imageView.image = image > } > // 3 > } > > > And: > > /// Shut down the current coroutine and give its memory back to the > /// shareholders. > func abandon() async -> Never { > await suspendAsync { _ = $0 } > } > > > Now, if I understand this correctly, the second thing is abandoning the task > from the context of the task by basically preventing the implicit callback of > abandon() to ever be called. > > But I don't see any way how the beginAsync {} block can be canceled after a > certain amount of time by the synchronous thread/context that is running at > location //3
This is not something the proposal aims to support, and as you noted, abrupt cancellation from outside a thread is not something you should generally do, and which is not really possible to do robustly with cooperatively-scheduled fibers like the coroutine proposal aims to provide. The section above is making the factual observation that, in our model, a coroutine once suspended can end up being dropped entirely by releasing all references to its continuation, and discusses the impact that possibility has on the model. This shouldn't be mistaken for proper cancellation support; as David noted, that's something you should still code explicit support for if you need it. -Joe _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution