es6-promise
- Version 4.2.8
- Published
- 315 kB
- No dependencies
- MIT license
Install
npm i es6-promise
yarn add es6-promise
pnpm add es6-promise
Overview
A lightweight library that provides tools for organizing asynchronous code
Index
Functions
function polyfill
polyfill: () => void;
The polyfill method will patch the global environment (in this case to the Promise name) when called.
Classes
class Promise
class Promise<R> implements Thenable<R> {}
constructor
constructor( callback: ( resolve: (value?: R | Thenable<R>) => void, reject: (error?: any) => void ) => void);
If you call resolve in the body of the callback passed to the constructor, your promise is fulfilled with result object passed to resolve. If you call reject your promise is rejected with the object passed to resolve. For consistency and debugging (eg stack traces), obj should be an instanceof Error. Any errors thrown in the constructor callback will be implicitly passed to reject().
method all
static all: { <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>, T10 | Thenable<T10> ] ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9> ] ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8> ] ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7> ] ): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6> ] ): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5> ] ): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>( values: [ T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4> ] ): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>( values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>] ): Promise<[T1, T2, T3]>; <T1, T2>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>]): Promise<[T1, T2]>; <T1>(values: [T1 | Thenable<T1>]): Promise<[T1]>; <TAll>(values: (TAll | Thenable<TAll>)[]): Promise<TAll[]>;};
Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. the array passed to all can be a mixture of promise-like objects and other objects. The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
method catch
catch: <U>(onRejected?: (error: any) => U | Thenable<U>) => Promise<U>;
Sugar for promise.then(undefined, onRejected)
Parameter onRejected
called when/if "promise" rejects
method finally
finally: (onFinally?: () => any | Thenable<any>) => Promise<R>;
onSettled is invoked when/if the "promise" settles (either rejects or fulfills). The returned promise is settled when the
Thenable
returned byonFinally
settles; it is rejected ifonFinally
throws or rejects; otherwise it assumes the state of the original Promise.Parameter onFinally
called when/if "promise" settles
method race
static race: <R>(promises: (R | Thenable<R>)[]) => Promise<R>;
Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
method reject
static reject: <R>(error: any) => Promise<R>;
Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
method resolve
static resolve: { (): Promise<void>; <R>(value: R | Thenable<R>): Promise<R> };
Make a new promise from the thenable. A thenable is promise-like in as far as it has a "then" method.
method then
then: { <U>( onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U> ): Promise<U>; <U>( onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void ): Promise<U>;};
onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. Both callbacks have a single parameter , the fulfillment value or rejection reason. "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. If an error is thrown in the callback, the returned promise rejects with that error.
Parameter onFulfilled
called when/if "promise" resolves
Parameter onRejected
called when/if "promise" rejects
Interfaces
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (24)
- babel-plugin-transform-es2015-arrow-functions
- babel-plugin-transform-es2015-block-scoping
- babel-plugin-transform-es2015-classes
- babel-plugin-transform-es2015-computed-properties
- babel-plugin-transform-es2015-constants
- babel-plugin-transform-es2015-destructuring
- babel-plugin-transform-es2015-parameters
- babel-plugin-transform-es2015-shorthand-properties
- babel-plugin-transform-es2015-spread
- babel-plugin-transform-es2015-template-literals
- babel6-plugin-strip-class-callcheck
- broccoli-babel-transpiler
- broccoli-concat
- broccoli-merge-trees
- broccoli-rollup
- broccoli-stew
- broccoli-uglify-js
- broccoli-watchify
- ember-cli
- ember-cli-dependency-checker
- git-repo-version
- json3
- mocha
- promises-aplus-tests-phantom
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/es6-promise
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/es6-promise)
- HTML<a href="https://www.jsdocs.io/package/es6-promise"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2920 ms. - Missing or incorrect documentation? Open an issue for this package.