9 releases
Uses old Rust 2015
0.1.7 | May 4, 2016 |
---|---|
0.1.6 | Apr 2, 2016 |
0.1.5 | Dec 22, 2015 |
0.1.4 | Aug 16, 2015 |
0.0.1 | Mar 31, 2015 |
#2059 in Asynchronous
584 downloads per month
Used in 4 crates
(2 directly)
125KB
2.5K
SLoC
Eventual - Futures & Streams for Rust
Eventual provides a Future & Stream abstraction for Rust as well as a number of computation builders to operate on them.
Usage
To use Eventual
, first add this to your Cargo.toml
:
[dependencies.eventual]
git = "https://github.com/carllerche/eventual"
Then, add this to your crate root:
extern crate eventual;
lib.rs
:
Composable primitives for asynchronous computations
The async module contains utilities for managing asynchronous computations.
These utilities are primarily based around Future
and Stream
types as
well as functions that allow composing computations on these types.
Future
A Future
is a proxy representing the result of a computation which may
not be complete. The computation may be running concurrently in another
thread or may be triggered upon completion of an asynchronous callback. One
way to think of a Future
is as a Result
where the value is
asynchronously computed.
For example:
use eventual::*;
// Run a computation in another thread
let future1 = Future::spawn(|| {
// Represents an expensive computation, but for now just return a
// number
42
});
// Run another computation
let future2 = Future::spawn(|| {
// Another expensive computation
18
});
let res = join((
future1.map(|v| v * 2),
future2.map(|v| v + 5)))
.and_then(|(v1, v2)| Ok(v1 - v2))
.await().unwrap();
assert_eq!(61, res);
Stream
A Stream
is like a Future
, except that instead of representing a single
value, it represents a sequence of values.
Dependencies
~0.9–1.2MB
~20K SLoC