reactive/kotlinx-coroutines-rx2/src/RxSingle.kt [15:55]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public fun rxSingle( context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T ): Single { require(context[Job] === null) { "Single context cannot contain job in it." + "Its lifecycle should be managed via Disposable handle. Had $context" } return rxSingleInternal(GlobalScope, context, block) } private fun rxSingleInternal( scope: CoroutineScope, // support for legacy rxSingle in scope context: CoroutineContext, block: suspend CoroutineScope.() -> T ): Single = Single.create { subscriber -> val newContext = scope.newCoroutineContext(context) val coroutine = RxSingleCoroutine(newContext, subscriber) subscriber.setCancellable(RxCancellable(coroutine)) coroutine.start(CoroutineStart.DEFAULT, coroutine, block) } private class RxSingleCoroutine( parentContext: CoroutineContext, private val subscriber: SingleEmitter ) : AbstractCoroutine(parentContext, false, true) { override fun onCompleted(value: T) { try { subscriber.onSuccess(value) } catch (e: Throwable) { handleUndeliverableException(e, context) } } override fun onCancelled(cause: Throwable, handled: Boolean) { try { if (subscriber.tryOnError(cause)) { return } } catch (e: Throwable) { cause.addSuppressed(e) } handleUndeliverableException(cause, context) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - reactive/kotlinx-coroutines-rx3/src/RxSingle.kt [15:55]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public fun rxSingle( context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T ): Single { require(context[Job] === null) { "Single context cannot contain job in it." + "Its lifecycle should be managed via Disposable handle. Had $context" } return rxSingleInternal(GlobalScope, context, block) } private fun rxSingleInternal( scope: CoroutineScope, // support for legacy rxSingle in scope context: CoroutineContext, block: suspend CoroutineScope.() -> T ): Single = Single.create { subscriber -> val newContext = scope.newCoroutineContext(context) val coroutine = RxSingleCoroutine(newContext, subscriber) subscriber.setCancellable(RxCancellable(coroutine)) coroutine.start(CoroutineStart.DEFAULT, coroutine, block) } private class RxSingleCoroutine( parentContext: CoroutineContext, private val subscriber: SingleEmitter ) : AbstractCoroutine(parentContext, false, true) { override fun onCompleted(value: T) { try { subscriber.onSuccess(value) } catch (e: Throwable) { handleUndeliverableException(e, context) } } override fun onCancelled(cause: Throwable, handled: Boolean) { try { if (subscriber.tryOnError(cause)) { return } } catch (e: Throwable) { cause.addSuppressed(e) } handleUndeliverableException(cause, context) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -