Skip to main content

Mojo struct

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 uses @explicit_destroy 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

Methods

__init__

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

Initialize a raising task with a raising coroutine.

Args:

  • handle (RaisingCoroutine): The raising coroutine to execute. Ownership is transferred.

__await__

__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

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.

Was this page helpful?