Crate promisery

Crate promisery 

Source
Expand description

§Promises for Rust

This crate provides a JavaScript-inspired, ergonomic, and composable Promise type for Rust, supporting background work, chaining, and error handling with Result.

§Features

  • ECMAScript 5-style promises with Rust’s type safety
  • Chaining with .then, .map, and .map_err
  • Combinators: Promise::all, Promise::race
  • Panic-safe: panics in promise tasks are detected and reported
  • Fully documented with tested examples
  • Timeout and deadline support: Use Promise::wait_timeout, Promise::wait_deadline to wait with timeouts or deadlines.
  • Safe and unsafe waiting: Use Promise::wait for panic-safe waiting, or Promise::wait_nopanic for unsafe, panic-propagating waiting.

§Example

use promisery::Promise;
let p = Promise::<_, ()>::new(|| Ok(2))
    .then(|res| res.map(|v| v * 10))
    .then(|res| res.map(|v| v + 5));
assert_eq!(p.wait(), Ok(Ok(25)));

§Error Handling

All errors are handled via Result<T, E>. Panics in promise tasks are reported via PromisePanic (see Promise::wait).

§Waiting for Results

§See Also


Released under the MIT License.

Structs§

Promise
A promise is a way of doing work in the background, similar to JavaScript promises.
PromisePanic
Error type returned when a promise panics during execution.

Enums§

WaitTimeoutError
Error type returned when waiting on a promise with a timeout.