0.0.3 • Published 4 years ago

unwait v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Unwait

Unwait makes it possible to access the properties and methods of async results before they are resolved, making Promise based APIs simpler and less verbose to work with. For example, with the Fetch API,

fetch("http://example.com/movies.json")
    .then((response) => {
        return response.json();
    })
    .then((movies) => {
        return movies.filter((movie) => movie.starRating === 5);
    })
    .then(/* process good movies */);

becomes:

unwait(fetch)("http://example.com/movies.json")
    .json()
    .filter((movie) => movie.starRating === 5)
    .then(/* process good movies */);

All access to functions, properties and methods will continue to be deferred until all promises in the chain are resolved. Each step in the chain can be awaited, then()'d or catch()ed like a regular Promise to recover it's value or handle any errors.

Installation

npm install unwait

Usage

const { unwait } = require("unwait");

const api = unwait(MyAPI);

Dependencies

Unwait uses the ES6 Proxy object. Because promised object properties are not known ahead of time, polyfills such as es2015-proxy-shim won't work - your javascript environment must support Proxy natively. See the support table here for more information.

There are no npm dependencies.

Contributing

After cloning the repository:

  • npm ci to install dependencies
  • npm run test to run jest specs
0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago