3 ms·
Concurrency: Implement withUnsafe[Throwing]Continuation
- jolux 6y agoPR written by Slava Pestov, the creator of Factor: https://factorcode.org https://factorcode.org
- rahimiali 6y agoi wish more languages provided call-cc. some languages let you freeze/restore a single stack frame, but it's unfashionable these days to freeze/restore an entire call chain. i find it to be a clean building block for all sorts of operations, like undo, multithreading, exception handling, etc. i missed this feature so much in python that i added it as a library [0]. [0] https://github.com/a-rahimi/python-checkpointing2 https://github.com/a-rahimi/python-checkpointing2
- viraptor 6y agoWouldn't it be safer to have a purpose-built state save and restore? This is a cool trick and will work in tightly controlled situations, but I wouldn't be comfortable using it with any third party library (so any non-trivial app) or if there's a chance of version update which changes state structure.
- anonymoushn 6y agoWhy not use greenlet? does it lack serializability?
- rahimiali 6y agogreenlet good! i'll check if it saves & restores the entire callchain or if it only works on the current frame like generators and async already do.
- anonymoushn 6y agoIt's real coroutines. I used it in production in 2010 before a worse thing made it into the language and in 2019 after.
- lilactown 6y agoI would prefer more languages provided delimited continuations, rather than “full” continuations like call/cc. See this paper by Oleg Okmij: http://okmij.org/ftp/continuations/against-callcc.html http://okmij.org/ftp/continuations/against-callcc.html
- anonymoushn 6y agoI would prefer more languages provided copyable coroutines, because I would rather explain create+switch+copy to people than call/cc or shift+reset
- slavapestov 6y agoThis isn’t “real” call/cc; the “continuation” here must be suspended and then resumed exactly once. It’s intended for writing async wrappers for callback-based APIs that take a completion function.
- sanxiyn 6y agoI saw the term "one-shot continuation" used to refer to this.
- slavapestov 6y agoYeah. This change doesn’t really introduce a new capability per se; it just ties together some of the existing concurrency primitives that other folks are working on in a new way.
- dang 6y agoOk, we've changed the title from "Swift to Add call/cc".
- The_rationalist 6y agoHow does this compare to Kotlin coroutines/continuations ?
- slavapestov 6y agoHere is an overview of the planned concurrency features: https://forums.swift.org/t/swift-concurrency-roadmap/41611 https://forums.swift.org/t/swift-concurrency-roadmap/41611
- comex 6y agoAs a low-level primitive to be used with await, only compatible with async functions. Which, if you think about it, is not as unusual as it sounds! In JavaScript, for instance, awaiting an object is equivalent to calling .then() on it, passing a closure which, when called, continues the function that awaited. In other words, JavaScript’s await is call/cc. It just uses .then() instead of a direct call, and has some extra complexity in the form of the ‘rejected’ callback. Other than that it’s the same thing. Edit: Well, except for the part where you can’t call the resume function more than once (I think?). Which is apparently also the case with this Swift version.
- deleted 6y ago[deleted]