#async #options #closed #atomic #return #async-mutex-option-t

async-option

Essentially an asynchronous Async<Mutex<Option<T>>>

2 releases

0.1.1 Mar 12, 2019
0.1.0 Mar 12, 2019

#1637 in Asynchronous

MIT license

19KB
305 lines

async-option

Crates.io Documentation Build Status Codecov

This crate provides an asynchronous, atomic Option type.

At a high level, this crate is exactly like Arc<Mutex<Option<T>>>, except with support for asynchronous operations. Given an Aption<T>, you can call poll_put to attempt to place a value into the Option, or poll_take to take a value out of the Option. Both methods will return Async::NotReady if the Option is occupied or empty respectively, and will at that point have scheduled for the current task to be notified when the poll_* call may succeed in the future. Aption<T> can also be used as a Sink<SinkItem = T> and Stream<Item = T> by effectively operating as a single-element channel.

An Aption<T> can also be closed using poll_close. Any poll_put after a poll_close will fail, and the next poll_take will return the current value (if any), and from then on poll_take will return an error.

Dependencies

~215KB