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: Nightly
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).

RaisingTask

struct RaisingTask[type: Movable, origins: OriginSet]

Represents an async task that may raise an error upon completion.

Wraps a RaisingCoroutine that executes asynchronously and either produces a result value or raises an error. The error is propagated to the caller when wait() is called.

This type does not conform to ImplicitlyDeletable because only one of the result or error slots is valid after completion. The caller must call wait() or force_destroy() to consume the task.

Parameters

  • type (Movable): The type of value produced on success.
  • origins (OriginSet): The set of origins for the coroutine wrapped by this task.

Implemented traits

AnyType, ImplicitlyDeletable

Methods

__init__

def __init__(out self, var handle: RaisingCoroutine[type, origins])

Initialize a raising task with a raising coroutine.

Args:

__await__

def __await__(deinit self, out result: type)

Suspend the current async function until the task completes.

Consumes the task. On success, moves the result out. On failure, raises the error from the coroutine.

This enables await task^ syntax in async functions.

Returns:

type: The result output parameter receives the task's result value.

Raises:

If the underlying coroutine raised an error.

wait

def wait(deinit self, out result: type)

Block until the task completes and return the result or raise.

Consumes the task. On success, moves the result out. On failure, raises the error from the coroutine.

Returns:

type: The result output parameter receives the task's result value.

Raises:

If the underlying coroutine raised an error.