1 | ;
|
2 | /*-----------------------------------------------------------------------------
|
3 | | Copyright (c) 2014-2017, PhosphorJS Contributors
|
4 | |
|
5 | | Distributed under the terms of the BSD 3-Clause License.
|
6 | |
|
7 | | The full license is in the file LICENSE, distributed with this software.
|
8 | |----------------------------------------------------------------------------*/
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | /**
|
11 | * A class which wraps a promise into a delegate object.
|
12 | *
|
13 | * #### Notes
|
14 | * This class is useful when the logic to resolve or reject a promise
|
15 | * cannot be defined at the point where the promise is created.
|
16 | */
|
17 | var PromiseDelegate = /** @class */ (function () {
|
18 | /**
|
19 | * Construct a new promise delegate.
|
20 | */
|
21 | function PromiseDelegate() {
|
22 | var _this = this;
|
23 | this.promise = new Promise(function (resolve, reject) {
|
24 | _this._resolve = resolve;
|
25 | _this._reject = reject;
|
26 | });
|
27 | }
|
28 | /**
|
29 | * Resolve the wrapped promise with the given value.
|
30 | *
|
31 | * @param value - The value to use for resolving the promise.
|
32 | */
|
33 | PromiseDelegate.prototype.resolve = function (value) {
|
34 | var resolve = this._resolve;
|
35 | resolve(value);
|
36 | };
|
37 | /**
|
38 | * Reject the wrapped promise with the given value.
|
39 | *
|
40 | * @reason - The reason for rejecting the promise.
|
41 | */
|
42 | PromiseDelegate.prototype.reject = function (reason) {
|
43 | var reject = this._reject;
|
44 | reject(reason);
|
45 | };
|
46 | return PromiseDelegate;
|
47 | }());
|
48 | exports.PromiseDelegate = PromiseDelegate;
|