[][src]Crate js_promises

Library for working with Javascript Promises using Rust code.

This crate contains two main types: RawPromise, which is a thin wrapper over JS's promise types, and Promise, which helps use promises with Rust types.

All methods that chain a promise currently translate to a then call, even if the result is available immediately. So doing as much synchronous work in one then call will be slightly more efficient than multiple then calls.

In promise callbacks, if a panic or JS error occurs, the library will print the error via console.error and return null from the promise.

Comparison to stdweb promises

  • stdweb promises, at the time of writing, require a feature to access, and are unstable. This... is also unstable but not locked behind a feature.
  • stdweb promises try to be compatible with the futures API, which does not map well to how JS promises and callbacks work. This crate exposes an API that mirrors JS's promises API.

Modules

jsbox

Functions for passing arbitrary Rust values across the JS boundary and back to Rust, ex. as a return value from a promise.

Structs

Promise

Typed promises, working with Rust types.

RawPromise

Wrapper for a JS promise, working with stdweb::Values.

Enums

PromiseOk

A non-error result from a promise; can be either an immediate Ok value, or another promise to execute.

Type Definitions

PromiseResult

Return type for Promise.then, which can be an immediate value to resolve to, another promise to run, or an immediate value to reject.