CoroutineContext: Is the context for coroutine persistence, which is a non-repeatable array in which each element has a unique key. Keys are compared by reference and are primarily used to build coroutine scopes.

open operator fun plus(
    context: CoroutineContext
): CoroutineContext
(source)
Copy the code

Returns an object of the current scope and an object of another scope. Objects in two scopes are removed if they are the same.

The JOB interface

interface Job : Element (source)

Job represents a background work task that can be canceled. Job is designed as a parent inheritance structure. If the parent job is canceled, the child job is also canceled recursively. In addition to CancellationException, child Job exceptions cause both the parent Job and its subclasses to be cancelled. (It is designed to be eliminated with the handling of the container.)

Deferred interface

This is a job that returns a result

interface Deferred<out T> : Job (source)

Deferred and Job have the same state machine and can retrieve the result of success or failure with await() method and throw an exception if it fails.

Functions on this interface, and all functions on its derived interfaces, are thread-safe.

CoroutineScope

interface CoroutineScope (source)

Coroutine context. Each coroutine constructor is an extension of the coroutineScope.

Use the plus operator to add a context object to the current scope.

CoroutineDispatcher

abstract class CoroutineDispatcher : ContinuationInterceptor (source)
Copy the code

Scheduling classes for coroutines.

ContinuationInterceptor

interface ContinuationInterceptor : Element
(source)
Copy the code

Flags coroutine context elements that intercept coroutine continuations. Coroutines framework USES ContinuationInterceptor. The Key to retrieve the interceptors, and through interceptContinuation call intercept all coroutines.

CoroutineExceptionHandler

interface CoroutineExceptionHandler : Element (source)
Copy the code

Optional element in the coroutine context for handling uncaught exceptions.

Typically, uncaught exceptions can only be generated by the root coroutine created using the start builder. All child coroutines (coroutines created in the context of another Job) delegate the handling of their exceptions to the parent coroutine, which delegates to the parent coroutine, and so on, all the way to the root, so that coroutines installed in their context are never used.

Coroutines that run with the container job won’t propagate exceptions to its parent coroutine and are treated as the root coroutine. A coroutine created using Async always catches all of its exceptions and represents them in the generated Deferred object, so it does not cause uncaught exceptions. CoroutineExceptionHandler