IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Coroutine

struct Coroutine[type: Deinitable, origins: OriginSet]

Represents a coroutine.

Coroutines can pause execution saving the state of the program (including values of local variables and the location of the next instruction to be executed). When the coroutine is resumed, execution continues from where it left off, with the saved state restored.

Parameters​

  • ​type (Deinitable): Type of value returned upon completion of the coroutine.
  • ​origins (OriginSet): The origin of the coroutine's captures.

Implemented traits​

AnyType, Movable, RegisterPassable

Methods​

__init__​

@implicit def __init__(handle: AnyCoroutine) -> Self

Construct a coroutine object from a handle.

Args:

__await__​

def __await__(deinit self, out result: type)

Suspends the current coroutine until the coroutine is complete.

Returns:

type: The coroutine promise.