pub struct AsyncCompletion<T> { /* private fields */ }Expand description
An async completion handler for FFI callbacks
This type provides a Future that resolves when an async callback completes.
It uses Arc<Mutex> internally for thread-safe signaling and waker management.
The raw context returned by Self::create is exact-live and one-shot.
Implementations§
Source§impl<T> AsyncCompletion<T>
impl<T> AsyncCompletion<T>
Sourcepub fn create() -> (AsyncCompletionFuture<T>, SyncCompletionPtr)
pub fn create() -> (AsyncCompletionFuture<T>, SyncCompletionPtr)
Create a new async completion handler and return the context pointer for FFI
Returns a tuple of (future, context_ptr) where:
futurecan be awaited to get the resultcontext_ptrshould be passed to the FFI callback
Sourcepub unsafe fn complete_ok(context: SyncCompletionPtr, value: T)
pub unsafe fn complete_ok(context: SyncCompletionPtr, value: T)
Signal successful completion with a value
§Safety
context must be the exact live pointer returned by
AsyncCompletion::create. This consumes the callback-owned Arc
reference and must be invoked exactly once for that context.
Sourcepub unsafe fn complete_err(context: SyncCompletionPtr, error: String)
pub unsafe fn complete_err(context: SyncCompletionPtr, error: String)
Signal completion with an error
§Safety
context must be the exact live pointer returned by
AsyncCompletion::create. This consumes the callback-owned Arc
reference and must be invoked exactly once for that context.
Sourcepub unsafe fn complete_with_result(
context: SyncCompletionPtr,
result: Result<T, String>,
)
pub unsafe fn complete_with_result( context: SyncCompletionPtr, result: Result<T, String>, )
Signal completion with a result
§Safety
context must be the exact pointer returned by
AsyncCompletion::create, its allocation must remain live for
this entire call, and foreign code must invoke this completion
exactly once and never use the pointer afterward.
The consumed flag only rejects a duplicate call while the
allocation is still live. It cannot validate an already-freed,
reused, or concurrently invalidated pointer.