https://github.com/jonhoo/async-option
Asynchronous Arc<Mutex<Option<T>>>
https://github.com/jonhoo/async-option
Last synced: 5 months ago
JSON representation
Asynchronous Arc<Mutex<Option<T>>>
- Host: GitHub
- URL: https://github.com/jonhoo/async-option
- Owner: jonhoo
- Created: 2019-03-11T21:26:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-03T16:08:35.000Z (about 7 years ago)
- Last Synced: 2025-10-14T15:42:54.784Z (10 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 15
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# async-option
[](https://crates.io/crates/async-option)
[](https://docs.rs/async-option/)
[](https://travis-ci.com/jonhoo/async-option)
[](https://codecov.io/gh/jonhoo/async-option)
This crate provides an asynchronous, atomic `Option` type.
At a high level, this crate is exactly like `Arc>>`, except with support for
asynchronous operations. Given an [`Aption`], 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` can also be used as a `Sink` and `Stream` by effectively operating as a single-element channel.
An `Aption` 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.
[`Aption`]: struct.Aption.html
[`poll_put`]: struct.Aption.html#method.poll_put
[`poll_take`]: struct.Aption.html#method.poll_take
[`poll_close`]: struct.Aption.html#method.poll_close