---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/vow.Promise.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# vow.Promise

A class which describes the promise objects.

[The Promise/A+ specification](https://github.com/promises-aplus/promises-spec).

{% note info %}

This class is a part of the [Vow](https://github.com/dfilatov/vow/) library. Only some of the methods are described below. The complete list of methods is available here: [http://dfilatov.github.io/vow/](http://dfilatov.github.io/vow/). Copyright (c) 2012-2013 Filatov Dmitry ([dfilatov@yandex-team.ru](mailto:dfilatov@yandex-team.ru)). Dual licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) and [GPL](http://www.gnu.org/licenses/gpl.html) licenses.

{% endnote %}

{% note info %}

It is not a stand-alone module: it is available only if the [vow](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.md) module is connected.

{% endnote %}

[Constructor](#constructor-summary) | [Methods](#methods-summary)

## Constructor {#constructor-summary}

```javascript
vow.Promise([resolver])
```

Creates a promise object.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`resolver`](#param-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:**

```javascript
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 {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [done](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#done)(\[[onFulfilled](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#done-param-onFulfilled)[, [onRejected](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#done-param-onRejected)[, [onProgress](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#done-param-onProgress)[, [ctx](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#done-param-ctx)]]]]) | | Similar to the method [vow.Promise.then](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then), which closes the promise chain. Throws an exception if the promise object is rejected. ||
|| [spread](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#spread)(\[[onFulfilled](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#spread-param-onFulfilled)[, [onRejected](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#spread-param-onRejected)[, [ctx](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#spread-param-ctx)]]]) | [vow.Promise](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md) | Similar to the method [vow.Promise.then](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#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](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.md#all). ||
|| [then](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then)(\[[onFulfilled](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then-param-onFulfilled)[, [onRejected](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then-param-onRejected)[, [onProgress](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then-param-onProgress)[, [ctx](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then-param-ctx)]]]]) | [vow.Promise](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md) | Specifies a handler function for a promise object. ||
|| [valueOf](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#valueOf)() | Object | Returns a value for an allowed promise object or a rejection reason for a rejected one.||
|#

## Methods details {#method_detail}

### done {#done}

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

Similar to the method [vow.Promise.then](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#then), which closes the promise chain. Throws an exception if the promise object is rejected.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`onFulfilled`](#done-param-onFulfilled) | — | Type: Function

The callback function which will be called if the promise object is resolved. ||
|| [`onRejected`](#done-param-onRejected) | — | Type: Function

The callback function which will be called if the promise object is rejected. ||
|| [`onProgress`](#done-param-onProgress) | — | Type: Function

The callback function which will be called when "notifying" the promise object. ||
|| [`ctx`](#done-param-ctx) | — | Type: Object

The execution context of the callback functions. ||
|#


**Example:**

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

### spread {#spread}

```javascript
{vow.Promise} spread([onFulfilled[, onRejected[, ctx]]])
```

Similar to the method [vow.Promise.then](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.Promise.md#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](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/vow.md#all).

**Returns** a new promise object.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`onFulfilled`](#spread-param-onFulfilled) | — | Type: Function

The callback function which will be called if the promise object is resolved. ||
|| [`onRejected`](#spread-param-onRejected) | — | Type: Function

The callback function which will be called if the promise object is rejected. ||
|| [`ctx`](#spread-param-ctx) | — | Type: Object

The execution context of the callback functions. ||
|#


**Example:**

```javascript
var deferred1 = ymaps.vow.defer();
var deferred2 = 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 {#then}

```javascript
{vow.Promise} then([onFulfilled[, onRejected[, onProgress[, ctx]]]])
```

Specifies a handler function for a promise object.

**Returns** a new promise object. See the [specification](https://github.com/promises-aplus/promises-spec).

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`onFulfilled`](#then-param-onFulfilled) | — | Type: Function

The callback function which will be called if the promise object is resolved. ||
|| [`onRejected`](#then-param-onRejected) | — | Type: Function

The callback function which will be called if the promise object is rejected. ||
|| [`onProgress`](#then-param-onProgress) | — | Type: Function

The callback function which will be called when "notifying" the promise object. ||
|| [`ctx`](#then-param-ctx) | — | Type: Object

The execution context of the callback functions. ||
|#

### valueOf {#valueOf}

```javascript
{Object} valueOf()
```

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

[*star]: Mandatory parameter/option.