The CoroutineResult<T> interface

The synchronous result obtained from calling a coroutine function.

A coroutine function call has four possible outcomes:

  1. It runs forever.
  2. It returns a value.
  3. It throws an exception.
  4. It suspends.

We disambiguate 2. from 4. by wrapping all returns in a wrapper class, and having a special "suspended" value, of a singleton type.

Interface synopsis

interface CoroutineResult {...}