Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement continuation cloning and SuspendCoroutine::suspendMultiple
Summary: This diff implements a rudimentary attempt at multi-shot continuations. You can read the design doc for the nitty-gritty. The high-level of this diff is the following: # Continuations are now represented by the interface `CloneableCoroutineContinuation` and provide a `clone` method. This method does a shallow-copy (i.e., copy-on-write) of the continuation's state (contained in the closure). Additionally, it does a `clone` on the next continuation in the chain. # The coroutines codegen now creates and passes around instances of `CloneableCoroutineContinuation`. However, the entry and exit points from the codegen only deal in `CoroutineContinuation`, so we don't expose cloning to the end user. (See remaining bullet points.) # `CreateCoroutine::createWithReceiverUnchecked` still receives a `CoroutineContinuation` as the completion callback. We now wrap the completion callback in a `NonCloningCoroutineContinuation`, which causes it to just return itself when someone tries to clone it. # `SuspendCoroutine::suspendMultiple` is a new suspend primitive for coroutines. It uses `CloneOnResumeContinuation` to allow multiple resumptions of a continuation, each of which are cloned from an original continuation. **Design doc:** https://fburl.com/multi-shot-continuations (IMPORTANT) **Big note/warning:** There are two things that we still need to do. (1) Copy-in the state before every suspension. I'll do this in the next diff. (2) Right now, when multi-suspending, we **recurse** into the resumed continuation. This is bad, because it may create deep call stacks, and we might stack overflow. I'll write up a design to fix this, but it will be fairly complex. This problem is isolated to the new `suspendMultiple` method, so existing code is unaffected. --- Reviewed By: ericlippert, vladima Differential Revision: D5790893 fbshipit-source-id: 510e97972927f21fff24c4d09bac2064df3ca7c9
- Loading branch information
1 parent
decf3f7
commit ab34a88
Showing
2 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters