start with promise status implementation
This commit is contained in:
parent
b15cdb48a3
commit
31c7e607cc
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -5,10 +5,12 @@ export interface IResolve<T> {
|
||||
export interface IReject {
|
||||
(reason?: any): void;
|
||||
}
|
||||
export declare type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
|
||||
export declare class Deferred<T> {
|
||||
promise: Promise<T>;
|
||||
resolve: IResolve<T>;
|
||||
reject: IReject;
|
||||
status: TDeferredStatus;
|
||||
constructor();
|
||||
}
|
||||
export declare let defer: <T>() => Deferred<T>;
|
||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -15,6 +15,7 @@ class Deferred {
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
this.status = 'pending';
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -53,4 +54,4 @@ exports.map = (inputArg, functionArg) => __awaiter(this, void 0, void 0, functio
|
||||
yield Promise.all(promiseArray);
|
||||
return resultArray;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsMEJBQXVCO0FBQ3ZCLDZCQUE0QjtBQVU1QjtJQUlFO1FBQ0UsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLE9BQU8sQ0FBSSxDQUFDLE9BQU8sRUFBRSxNQUFNO1lBQzVDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFBO1lBQ3RCLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFBO1FBQ3RCLENBQUMsQ0FBQyxDQUFBO0lBQ0osQ0FBQztDQUNGO0FBVkQsNEJBVUM7QUFFVSxRQUFBLEtBQUssR0FBRztJQUNq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QUFFVSxRQUFBLFNBQVMsR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFBO0FBRXJDLFdBQVc7QUFDWCxFQUFFLENBQUMsQ0FBQyxDQUFDLGlCQUFTLENBQUMsQ0FBQyxDQUFDO0lBQ2YsaUJBQVMsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtBQUN2QyxDQUFDO0FBQ1UsUUFBQSxHQUFHLEdBQUcsQ0FBVyxRQUFhLEVBQUMsV0FBVztJQUNuRCxJQUFJLGtCQUFrQixHQUFHLGlCQUFTLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDL0MsSUFBSSxZQUFZLEdBQW1CLEVBQUUsQ0FBQTtJQUNyQyxJQUFJLFdBQVcsR0FBRyxFQUFFLENBQUE7SUFDcEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksUUFBUSxDQUFDLENBQUMsQ0FBQztRQUMxQixJQUFJLE9BQU8sR0FBaUIsa0JBQWtCLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDcEQsWUFBWSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUMxQixPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDWixXQUFXLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3JCLENBQUMsQ0FBQyxDQUFBO0lBRUosQ0FBQztJQUNELE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQTtJQUMvQixNQUFNLENBQUMsV0FBVyxDQUFBO0FBQ3BCLENBQUMsQ0FBQSxDQUFBIn0=
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
34
test/test.js
34
test/test.js
@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const smartchai_1 = require("smartchai");
|
||||
const q = require("../dist/index");
|
||||
let myCallback = (someValue1, cb) => {
|
||||
cb(null, someValue1);
|
||||
};
|
||||
describe('smartq', function () {
|
||||
it('should return a Deferred for .defer()', function () {
|
||||
let myDeferred = q.defer();
|
||||
let expectPromise = smartchai_1.expect(myDeferred.promise).to.eventually.be.fulfilled;
|
||||
myDeferred.resolve();
|
||||
return expectPromise;
|
||||
});
|
||||
it('should let types flow through the Promise', function () {
|
||||
let myString = 'someString';
|
||||
let myDeferred = q.defer();
|
||||
let expectPromise = smartchai_1.expect(myDeferred.promise).to.eventually.equal('someString');
|
||||
myDeferred.resolve(myString);
|
||||
return expectPromise;
|
||||
});
|
||||
it('should promisify a callback', function () {
|
||||
let myPromisified = q.promisify(myCallback);
|
||||
let expectPromise = smartchai_1.expect(myPromisified('hi')).to.eventually.equal('hi');
|
||||
return expectPromise;
|
||||
});
|
||||
it('should map callbacks', function () {
|
||||
let inputArray = ['hi', 'awesome'];
|
||||
let myPromisified = q.promisify(myCallback);
|
||||
let expectPromise = smartchai_1.expect(q.map(inputArray, myPromisified)).to.eventually.deep.equal(inputArray);
|
||||
return expectPromise;
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQix5Q0FBa0M7QUFDbEMsbUNBQWtDO0FBRWxDLElBQUksVUFBVSxHQUFHLENBQUMsVUFBa0IsRUFBRSxFQUFHO0lBQ3JDLEVBQUUsQ0FBQyxJQUFJLEVBQUUsVUFBVSxDQUFDLENBQUE7QUFDeEIsQ0FBQyxDQUFBO0FBRUQsUUFBUSxDQUFDLFFBQVEsRUFBRTtJQUNmLEVBQUUsQ0FBQyx1Q0FBdUMsRUFBRTtRQUN4QyxJQUFJLFVBQVUsR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDMUIsSUFB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2xDLElBQUksYUFBYSxHQUFHLENBQUMsQ0FBQyxTQUFTLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDM0MsSUFBSSxhQUFhLEdBQUcsa0JBQU0sQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLFVBQVUsRUFBRSxhQUFhLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNqRyxNQUFNLENBQUMsYUFBYSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
@ -9,14 +9,18 @@ export interface IReject {
|
||||
(reason?: any): void
|
||||
}
|
||||
|
||||
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected'
|
||||
|
||||
export class Deferred<T> {
|
||||
promise: Promise<T>
|
||||
resolve: IResolve<T>
|
||||
reject: IReject
|
||||
constructor() {
|
||||
status: TDeferredStatus
|
||||
constructor () {
|
||||
this.promise = new Promise<T>((resolve, reject) => {
|
||||
this.resolve = resolve
|
||||
this.reject = reject
|
||||
this.status = 'pending'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user