1 unstable release

0.1.0 Nov 8, 2019

#1122 in WebAssembly

MIT license

27KB
462 lines

Rust crate for using and manipulating JS Promise objects, using stdweb.

Contains two major types:

  • RawPromise, a lightweight wrapper for a JS promise. These work with raw stdweb::Values. It provides Rust methods for chaining promises with Rust functions, handling cleanup.
  • Promise<TOk, TErr>, a more featureful wrapper that is capable of sending arbitrary Rust types.

lib.rs:

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.

Dependencies

~3MB
~68K SLoC