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

Mojo struct

AnyAsyncValueRef

struct AnyAsyncValueRef

Owning, reference-counted handle to a C++ AsyncValue -- a limited Mojo counterpart of the C++ AnyAsyncValueRef / RCRef[AsyncValue].

Holds a pointer to the AsyncValue; copying retains (adds one reference) and destruction releases one. A null handle is the empty / non-tracked reference. Used as the storage handle of an OwnedByteBuffer, mirroring the storageRef field of the C++ TensorBufferRef.

Implemented traits​

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods​

__init__​

def __init__(out self)

Creates an empty (null) AsyncValue reference.

def __init__(out self, handle: Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]])

Adopts an already-owning handle net-zero (does not retain).

Args:

def __init__(out self, *, copy: Self)

Creates a new owning reference by retaining the shared AsyncValue.

Args:

  • ​copy (Self): The reference to copy.

def __init__(out self, *, retained_storage_of: Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]])

Retains the backing storage of a packed async value into a new ref.

Reads the AsyncValue* of the packed buffer/tensor value and adds one reference to its storage handle, so the returned handle independently keeps the backing memory alive (e.g. when an unpacked value is re-packed).

Args:

def __init__(out self, *, take_slot: Pointer[NoneType, MutAnyOrigin])

Moves the AsyncValue out of a runtime-owned slot and nulls the slot.

Takes ownership of the single reference stored in the C++ AnyAsyncValueRef pointed to by take_slot, resets the slot to empty, and adopts the reference without retaining.

Args:

def __init__(out self, *, var storage_buf: DeviceBuffer)

Wraps a live owning DeviceBuffer in an AsyncValue[DeviceBufferRef].

The buffer's handle is surrendered net-zero (take_handle) and adopted by the runtime, so no extra reference is created.

Args:

  • ​storage_buf (DeviceBuffer): The owning device buffer to wrap.

__deinit__​

def __deinit__(deinit self)

Releases this reference to the underlying AsyncValue.

get_handle​

def get_handle(self) -> Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]]

Returns the underlying AsyncValue* without transferring ownership.

The returned pointer remains valid only as long as this AnyAsyncValueRef keeps the underlying AsyncValue alive.

Returns:

Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]]: The AsyncValue* backing this type. The handle is still held and managed by the AnyAsyncValueRef.

take_handle​

def take_handle(deinit self) -> Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]]

Surrenders the owning handle net-zero, suppressing the destructor.

Returns:

Optional[Pointer[_AsyncValueCpp, MutUntrackedOrigin]]: The owning AsyncValue*; the caller must hand it to a runtime owner that adopts it without an extra reference.

Was this page helpful?