Documentation
Reference
2.1.56 (current version)
collection
interactivityModel
Interfaces

vow.Promise

A class which describes the promise objects.

The Promise/A+ specification.

Note.  This class is a part of the Vow library. Only some of the methods are described below. The complete list of methods is available here: http://dfilatov.github.io/vow/. Copyright (c) 2012-2013 Filatov Dmitry (dfilatov@yandex-team.ru). Dual licensed under the MIT and GPL licenses.

Note. It is not a stand-alone module: it is available only if the vow module is connected.

Constructor | Methods

Constructor

vow.Promise([resolver])

Creates a promise object.

Parameters:

ParameterDefault valueDescription
resolver

Type: Function

The function which takes the resolve and reject methods as parameters to set status and values for the created promise object.

Example:

function someAsyncMethod () {
    return new ymaps.vow.Promise(function (resolve, reject) {
        doSomeAsyncStuff(function (err, value) {
            if (err) {
                reject(err);
                return;
            }

            resolve(value);
        });
    });
}

someAsyncMethod().then(function (value) {
    console.log('The method result: ' + value);
}, function (err) {
    console.log('Error: ' + err);
});

Methods

NameReturnsDescription
done([onFulfilled[, onRejected[, onProgress[, ctx]]]])

Similar to the method vow.Promise.then, which closes the promise chain. Throws an exception if the promise object is rejected.

spread([onFulfilled[, onRejected[, ctx]]])

vow.Promise

Similar to the method vow.Promise.then, which calls the callback functions with a set of arguments (corresponding to an array) for which the promise object can be either allowed or rejected. Usually it is used in combination with methods like vow.all.

then([onFulfilled[, onRejected[, onProgress[, ctx]]]])

vow.Promise

Specifies a handler function for a promise object.

valueOf()

Object

Returns a value for an allowed promise object or a rejection reason for a rejected one.

Methods details

done

{} done([onFulfilled[, onRejected[, onProgress[, ctx]]]])

Similar to the method vow.Promise.then, which closes the promise chain. Throws an exception if the promise object is rejected.

Parameters:

ParameterDefault valueDescription
onFulfilled

Type: Function

The callback function which will be called if the promise object is resolved.

onRejected

Type: Function

The callback function which will be called if the promise object is rejected.

onProgress

Type: Function

The callback function which will be called when "notifying" the promise object.

ctx

Type: Object

The execution context of the callback functions.

Example:

var deferred = ymaps.vow.defer();
deferred.reject(Error('Internal error'));
deferred.promise().done(); // Throws an exception.

spread

Similar to the method vow.Promise.then, which calls the callback functions with a set of arguments (corresponding to an array) for which the promise object can be either allowed or rejected. Usually it is used in combination with methods like vow.all.

Returns a new promise object.

Parameters:

ParameterDefault valueDescription
onFulfilled

Type: Function

The callback function which will be called if the promise object is resolved.

onRejected

Type: Function

The callback function which will be called if the promise object is rejected.

ctx

Type: Object

The execution context of the callback functions.

Example:

var deferred1 = ymaps.vow.defer(),
    deferedr2 = ymaps.vow.defer();

ymaps.vow.all([deferred1.promise(), deferred2.promise()]).spread(function(arg1, arg2) {
    // arg1 => 1, arg2 => 'two'
});

deferred1.resolve(1);
deferred2.resolve('two');

then

Specifies a handler function for a promise object.

Returns a new promise object. See the specification.

Parameters:

ParameterDefault valueDescription
onFulfilled

Type: Function

The callback function which will be called if the promise object is resolved.

onRejected

Type: Function

The callback function which will be called if the promise object is rejected.

onProgress

Type: Function

The callback function which will be called when "notifying" the promise object.

ctx

Type: Object

The execution context of the callback functions.

valueOf

{Object} valueOf()

Returns a value for an allowed promise object or a rejection reason for a rejected one.