prex-es5
Version:
Async coordination primitives and extensions on top of ES6 Promises
45 lines (42 loc) • 1.12 kB
JavaScript
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0.
See LICENSE file in the project root for details.
***************************************************************************** */
/**
* Encapsulates a Promise and exposes its resolve and reject callbacks.
*/
export class Deferred {
/**
* Initializes a new instance of the Deferred class.
*/
constructor() {
this._promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
/**
* Gets the promise.
*/
get promise() {
return this._promise;
}
/**
* Resolves the promise.
*
* @param value The value used to resolve the promise.
*/
resolve(value) {
this._resolve(value);
}
/**
* Rejects the promise.
*
* @param reason The reason the promise was rejected.
*/
reject(reason) {
this._reject(reason);
}
}
//# sourceMappingURL=deferred.js.map