EN RU
Форум

Методология

Технологии

Инструментарий

Библиотеки

Учебные материалы

DocumentationJSDocSource

vow

Блок предоставляет библиотеку Vow.

Vow – библиотека для работы с промисами, реализующая стандарт Promises/A+ и поддержку спецификации ES6 Promises.

Использование

modules.require(['vow'], function(vow) {
    // ...
});

С полным API библиотеки вы можете ознакомиться здесь.

Публичные технологии блока

Блок реализован в технологиях:

  • vanilla.js

Module vow

Object methods:

Deferred()
description
The `Deferred` class is used to encapsulate newly-created promise object along with functions that resolve, reject or notify it.
Promise()
description
The `Promise` class is used when you want to give to the caller something to subscribe to, but not the ability to resolve or reject the deferred.
defer():vow:Deferred
description
Creates a new deferred. This method is a factory method for `vow:Deferred` class. It's equivalent to `new vow.Deferred()`.
when(value, [onFulfilled], [onRejected], [onProgress], [ctx]):vow:Promise
description
Static equivalent to `promise.then`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
onProgress
Function
Callback that will be invoked with a provided value after the promise has been notified
ctx
Object
Context of the callbacks execution
fail(value, onRejected, [ctx]):vow:Promise
description
Static equivalent to `promise.fail`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
ctx
Object
Context of the callback execution
always(value, onResolved, [ctx]):vow:Promise
description
Static equivalent to `promise.always`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onResolved
Function
Callback that will be invoked with the promise as an argument, after the promise has been resolved.
ctx
Object
Context of the callback execution
progress(value, onProgress, [ctx]):vow:Promise
description
Static equivalent to `promise.progress`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onProgress
Function
Callback that will be invoked with a provided value after the promise has been notified
ctx
Object
Context of the callback execution
spread(value, [onFulfilled], [onRejected], [ctx]):vow:Promise
description
Static equivalent to `promise.spread`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
ctx
Object
Context of the callbacks execution
done(value, [onFulfilled], [onRejected], [onProgress], [ctx])
description
Static equivalent to `promise.done`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
onProgress
Function
Callback that will be invoked with a provided value after the promise has been notified
ctx
Object
Context of the callbacks execution
isPromise(value):Boolean
description
Checks whether the given `value` is a promise-like object
parameters
value
*
cast(value):vow:Promise
description
Coerces the given `value` to a promise, or returns the `value` if it's already a promise.
parameters
value
*
valueOf(value):Any
description
Static equivalent to `promise.valueOf`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
isFulfilled(value):Boolean
description
Static equivalent to `promise.isFulfilled`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
isRejected(value):Boolean
description
Static equivalent to `promise.isRejected`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
isResolved(value):Boolean
description
Static equivalent to `promise.isResolved`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
resolve(value):vow:Promise
description
Returns a promise that has already been resolved with the given `value`. If `value` is a promise, the returned promise will have `value`'s state.
parameters
value
*
fulfill(value):vow:Promise
description
Returns a promise that has already been fulfilled with the given `value`. If `value` is a promise, the returned promise will be fulfilled with the fulfill/rejection value of `value`.
parameters
value
*
reject(reason):vow:Promise
description
Returns a promise that has already been rejected with the given `reason`. If `reason` is a promise, the returned promise will be rejected with the fulfill/rejection value of `reason`.
parameters
reason
*
invoke(fn, [args]):vow:Promise
description
Invokes the given function `fn` with arguments `args`
parameters
fn
Function
args
...*
all(iterable):vow:Promise
description
Returns a promise, that will be fulfilled only after all the items in `iterable` are fulfilled. If any of the `iterable` items gets rejected, the promise will be rejected.
parameters
iterable
Array, Object
allResolved(iterable):vow:Promise
description
Returns a promise, that will be fulfilled only after all the items in `iterable` are resolved.
parameters
iterable
Array, Object
any(iterable):vow:Promise
description
Returns a promise, that will be fulfilled if any of the items in `iterable` is fulfilled. If all of the `iterable` items get rejected, the promise will be rejected (with the reason of the first rejected item).
parameters
iterable
Array
anyResolved(iterable):vow:Promise
description
Returns a promise, that will be fulfilled only when any of the items in `iterable` is fulfilled. If any of the `iterable` items gets rejected, the promise will be rejected.
parameters
iterable
Array
delay(value, delay):vow:Promise
description
Static equivalent to `promise.delay`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
delay
Number
timeout(value, timeout):vow:Promise
description
Static equivalent to `promise.timeout`. If `value` is not a promise, then `value` is treated as a fulfilled promise.
parameters
value
*
timeout
Number

Class Deferred

Instance methods:

promise():vow:Promise
description
Returns the corresponding promise.
resolve(value)
description
Resolves the corresponding promise with the given `value`.
parameters
value
*
reject(reason)
description
Rejects the corresponding promise with the given `reason`.
parameters
reason
*
notify(value)
description
Notifies the corresponding promise with the given `value`.
parameters
value
*

Class Promise

Instance methods:

valueOf():Any
description
Returns the value of the fulfilled promise or the reason in case of rejection.
isResolved():Boolean
description
Returns `true` if the promise is resolved.
isFulfilled():Boolean
description
Returns `true` if the promise is fulfilled.
isRejected():Boolean
description
Returns `true` if the promise is rejected.
then([onFulfilled], [onRejected], [onProgress], [ctx]):vow:Promise
description
Adds reactions to the promise.
parameters
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
onProgress
Function
Callback that will be invoked with a provided value after the promise has been notified
ctx
Object
Context of the callbacks execution
catch(onRejected, [ctx]):vow:Promise
description
Adds only a rejection reaction. This method is a shorthand for `promise.then(undefined, onRejected)`.
parameters
onRejected
Function
Callback that will be called with a provided 'reason' as argument after the promise has been rejected
ctx
Object
Context of the callback execution
fail(onRejected, [ctx]):vow:Promise
description
Adds only a rejection reaction. This method is a shorthand for `promise.then(null, onRejected)`. It's also an alias for `catch`.
parameters
onRejected
Function
Callback to be called with the value after promise has been rejected
ctx
Object
Context of the callback execution
always(onResolved, [ctx]):vow:Promise
description
Adds a resolving reaction (for both fulfillment and rejection).
parameters
onResolved
Function
Callback that will be invoked with the promise as an argument, after the promise has been resolved.
ctx
Object
Context of the callback execution
progress(onProgress, [ctx]):vow:Promise
description
Adds a progress reaction.
parameters
onProgress
Function
Callback that will be called with a provided value when the promise has been notified
ctx
Object
Context of the callback execution
spread([onFulfilled], [onRejected], [ctx]):vow:Promise
description
Like `promise.then`, but "spreads" the array into a variadic value handler. It is useful with the `vow.all` and the `vow.allResolved` methods.
parameters
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
ctx
Object
Context of the callbacks execution
done([onFulfilled], [onRejected], [onProgress], [ctx])
description
Like `then`, but terminates a chain of promises. If the promise has been rejected, this method throws it's "reason" as an exception in a future turn of the event loop.
parameters
onFulfilled
Function
Callback that will be invoked with a provided value after the promise has been fulfilled
onRejected
Function
Callback that will be invoked with a provided reason after the promise has been rejected
onProgress
Function
Callback that will be invoked with a provided value after the promise has been notified
ctx
Object
Context of the callbacks execution
delay(delay):vow:Promise
description
Returns a new promise that will be fulfilled in `delay` milliseconds if the promise is fulfilled, or immediately rejected if the promise is rejected.
parameters
delay
Number
timeout(timeout):vow:Promise
description
Returns a new promise that will be rejected in `timeout` milliseconds if the promise is not resolved beforehand.
parameters
timeout
Number

Static methods:

cast(value):vow:Promise
description
Coerces the given `value` to a promise, or returns the `value` if it's already a promise.
parameters
value
*
all(iterable):vow:Promise
description
Returns a promise, that will be fulfilled only after all the items in `iterable` are fulfilled. If any of the `iterable` items gets rejected, then the returned promise will be rejected.
parameters
iterable
Array, Object
race(iterable):vow:Promise
description
Returns a promise, that will be fulfilled only when any of the items in `iterable` are fulfilled. If any of the `iterable` items gets rejected, then the returned promise will be rejected.
parameters
iterable
Array
resolve(value):vow:Promise
description
Returns a promise that has already been resolved with the given `value`. If `value` is a promise, the returned promise will have `value`'s state.
parameters
value
*
reject(reason):vow:Promise
description
Returns a promise that has already been rejected with the given `reason`.
parameters
reason
*

Constructor

parameters
resolver
Function
See https://github.com/domenic/promises-unwrapping/blob/master/README.md#the-promise-constructor for details.