promiseslib
v0.1.1
Published
The missing Promise helpers your project needs
Downloads
4
Readme
The missing Promise
helpers your project needs—just contains a few helpers that can benefit your project.
Ships as an ES module.
Requires a native implementation of Promise
(maybe a polyfill will work too), and support for async
and await
.
You might be able to transpile these requirements away for older browsers.
Usage
Add to your dependencies via NPM or Yarn.
import * as promises from './node_modules/promiseslib/index.js'; // or
import * as promises from 'promiseslib'; // maybe, but must be transpiled
If you're feeling lazy, open this file in RawGit and use the latest production link. This won't provide you with updates but it is easy to include whole "https://..." paths via ES modules.
Methods
promises.sleep(ms)
: builds aPromise
which resolves after a specified time (or a frame if negative, or microtask if null/undefined is passed)promises.event(target, event)
: builds aPromise
which resolves when the given event occurspromises.dedup(fn, ms)
: builds a dedup function which delays calls until the last in the specified period, all calls return the same sharedPromise
representing the completion of the last callpromises.makeSingle(generator)
: converts a generator (that yieldsPromise
instances) into a task that can only run at most once (read more)promises.group(callback)
: builds a wait group; aka a function which, when called with aPromise
, returns a newPromise
that waits for all passed promises to complete before resolving