promisery 1.1.0

A JavaScript-inspired, ergonomic, and composable Promise type for Rust, supporting background work, chaining, and error handling with Result.
Documentation

promisery

Crates.io Docs.rs License

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 (see Promise::wait_nopanic)
  • Fully documented with tested examples

Installation

Add to your Cargo.toml:

promisery = "1.0.0"

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(25));

API Highlights

  • Chaining:
    • .then for full control over result and error
    • .map for value transformation
    • .map_err for error transformation
  • Combinators:
    • Promise::all waits for all promises
    • Promise::race resolves/rejects with the first to finish
  • Panic Handling:
    • Panics in promise tasks are detected and reported via PromisePanic
    • Use .wait_nopanic() to safely handle panics

Why promisery?

  • Lightweight, no async runtime required
  • Familiar API for those coming from JavaScript
  • Integrates with Rust's Result-based error handling
  • Does not spawn a new thread for each action that produces a new promise (see the documentation for each method for more details)

License

MIT OR Apache-2.0


See docs.rs/promisery for full documentation and more examples.