releaseInterceptedContinuation clarified and ref check in impl fixed

This commit is contained in:
Roman Elizarov
2018-07-03 14:16:04 +03:00
committed by Denis Zharkov
parent d33409ff8a
commit 38c17249b9
2 changed files with 6 additions and 4 deletions
@@ -101,7 +101,7 @@ internal abstract class ContinuationImpl protected constructor(
protected override fun releaseIntercepted() {
val intercepted = intercepted
if (intercepted != null && intercepted != this) {
if (intercepted != null && intercepted !== this) {
context[ContinuationInterceptor]!!.releaseInterceptedContinuation(intercepted)
}
this.intercepted = CompletedContinuation // just in case
@@ -24,14 +24,16 @@ public interface ContinuationInterceptor : CoroutineContext.Element {
*
* This function may simply return original [continuation] if it does not want to intercept this particular continuation.
*
* When the original [continuation] completes coroutine framework invokes [releaseInterceptedContinuation]
* with the resulting continuation if it was intercepted.
* When the original [continuation] completes, coroutine framework invokes [releaseInterceptedContinuation]
* with the resulting continuation if it was intercepted, that is if `interceptContinuation` had previously
* returned a different continuation instance.
*/
public fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T>
/**
* Invoked for the continuation instance returned by [interceptContinuation] when the original
* continuation completes and will not be used anymore.
* continuation completes and will not be used anymore. This function is invoked only if [interceptContinuation]
* had returned a different continuation instance from the one it was invoked with.
*
* Default implementation does nothing.
*