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.
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
The context pointer must be a valid pointer obtained from AsyncCompletion::new().
This function consumes the Arc reference, so it must only be called once per 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
The context pointer must be a valid pointer obtained from AsyncCompletion::new().
This function consumes the Arc reference, so it must only be called once per 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
The context pointer must be a valid pointer obtained from
AsyncCompletion::create() and not yet freed. The intended FFI
contract is that the callback fires exactly once per context.
The consumed AtomicBool provides defence in depth against
Swift firing the callback twice on the same still-live
allocation. The same residual UAF contract documented on
SyncCompletion::complete_with_result applies here: a third
callback after both the legitimate fire AND the consumer’s drop
of the AsyncCompletionFuture would dereference a freed
pointer. Apple’s APIs do not exhibit that pattern.
§Panics
Panics if the internal mutex is poisoned.