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

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, ImplicitlyCopyable, ImplicitlyDeletable, Movable

Methods

__init__

def __init__(out self)

Creates an empty (null) AsyncValue reference.

def __init__(out self, handle: Optional[UnsafePointer[_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: UnsafePointer[NoneType, MutAnyOrigin])

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

Reads the AsyncValue* behind the slot's TensorBufferRef storage handle and adds one reference, so the returned handle independently keeps the backing memory alive (e.g. when an unpacked value is re-packed).

Args:

def __init__(out self, *, retain_handle: UnsafePointer[NoneType, MutAnyOrigin])

Retains an existing AnyAsyncValueRef storage handle into a new ref.

Reads the AsyncValue* behind the given C++ AnyAsyncValueRef handle (e.g. a cached buffer's memory handle) and adds one reference. A null handle yields the empty (non-tracked) reference.

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.

__del__

def __del__(deinit self)

Releases this reference to the underlying AsyncValue.

take_handle

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

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

Returns:

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