Thanks for looking that up. Where did you find it? There isn’t any other obvious place where it would come from, but I didn’t think that getting it from the completion was really obvious either. At the time I didn’t otherwise care what context was used to resume the completion, so I used EmptyCoroutineContext
I’m using these methods in the implementation of this super-fun function, which is part of an Input/OutputStream replacement library:
/**
* Create a coroutine that is executed incrementally as the returned
* iterator is advanced.
*
* Until the end of the iterated sequence, the coroutine only executes
* during calls to [Iterator.next].
*
* Each call to [Iterator.next] returns a suspending function that
* should be called before [Iterator.next] is called again. These functions
* are produced out to the caller whenever the coroutine suspends, and
* calling the produced function will delay until the coroutine is ready to
* proceed.
*
* Suspending functions can also be produced out to the caller via
* [IncrementalScope.yield] on the block's receiver.
*
* If the caller fails to call a produced suspending function when required,
* or fails to interact with other side-effects of the coroutine in any
* required way, then the coroutine should terminate as soon as it regains
* control.
*
* When the coroutine terminates, or when it is cancelled via cancellation
* of the [Job] in the parent [CoroutineScope], any remaining (clean up) work
* will be launched in the parent scope, and subsequent calls to [Iterator.hasNext]
* will return false.
*/
fun CoroutineScope.launchIncremental(block: suspend IncrementalScope.() -> Unit)
:Iterator<suspend () -> Unit> {
TODO()
}