initial
This commit is contained in:
parent
f55ebefffb
commit
de3f582226
15
dist/index.d.ts
vendored
Normal file
15
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import 'typings-global';
|
||||
export interface IResolve<T> {
|
||||
(value?: T | Promise<T>): void;
|
||||
}
|
||||
export interface IReject {
|
||||
(reason?: any): void;
|
||||
}
|
||||
export declare class Deferred<T> {
|
||||
promise: Promise<T>;
|
||||
resolve: IResolve<T>;
|
||||
reject: IReject;
|
||||
constructor();
|
||||
}
|
||||
export declare let defer: <T>() => Deferred<T>;
|
||||
export declare let all: () => void;
|
17
dist/index.js
vendored
Normal file
17
dist/index.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
class Deferred {
|
||||
constructor() {
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Deferred = Deferred;
|
||||
exports.defer = () => {
|
||||
return new Deferred();
|
||||
};
|
||||
exports.all = () => {
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBVXZCO0lBSUk7UUFDSSxJQUFJLENBQUMsT0FBTyxHQUFHLElBQUksT0FBTyxDQUFJLENBQUMsT0FBTyxFQUFFLE1BQU07WUFDMUMsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUE7WUFDdEIsSUFBSSxDQUFDLE1BQU0sR0FBRyxNQUFNLENBQUE7UUFDeEIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBQ0o7QUFWRCw0QkFVQztBQUVVLFFBQUEsS0FBSyxHQUFHO0lBQ2YsTUFBTSxDQUFDLElBQUksUUFBUSxFQUFLLENBQUE7QUFDNUIsQ0FBQyxDQUFBO0FBR1UsUUFBQSxHQUFHLEdBQUc7QUFFakIsQ0FBQyxDQUFBIn0=
|
10
package.json
10
package.json
@ -16,5 +16,13 @@
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartq/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartq#README"
|
||||
"homepage": "https://gitlab.com/pushrocks/smartq#README",
|
||||
"dependencies": {
|
||||
"typings-global": "^1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.2",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
}
|
||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import 'typings-test';
|
23
test/test.js
Normal file
23
test/test.js
Normal file
@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const should = require("should");
|
||||
const q = require("../dist/index");
|
||||
describe('smartq', function () {
|
||||
it('should return a Deferred for .defer()', function (done) {
|
||||
let myDeferred = q.defer();
|
||||
myDeferred.promise.then(() => {
|
||||
done();
|
||||
});
|
||||
myDeferred.resolve();
|
||||
});
|
||||
it('should let types flow through the Promise', function (done) {
|
||||
let myString = 'someString';
|
||||
let myDeferred = q.defer();
|
||||
myDeferred.promise.then(x => {
|
||||
should(x).equal('someString');
|
||||
done();
|
||||
});
|
||||
myDeferred.resolve(myString);
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixpQ0FBZ0M7QUFDaEMsbUNBQWtDO0FBRWxDLFFBQVEsQ0FBQyxRQUFRLEVBQUU7SUFDZixFQUFFLENBQUMsdUNBQXVDLEVBQUUsVUFBUyxJQUFJO1FBQ3JELElBQUksVUFBVSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUMxQixVQUFVLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQztZQUNwQixJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsVUFBVSxDQUFDLE9BQU8sRUFBRSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0lBRUYsRUFBRSxDQUFDLDJDQUEyQyxFQUFFLFVBQVMsSUFBSTtRQUN6RCxJQUFJLFFBQVEsR0FBRyxZQUFZLENBQUE7UUFDM0IsSUFBSSxVQUFVLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBVSxDQUFBO1FBQ2xDLFVBQVUsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDckIsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQTtZQUM3QixJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsVUFBVSxDQUFDLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQTtJQUNoQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
24
test/test.ts
Normal file
24
test/test.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import 'typings-test'
|
||||
|
||||
import * as should from 'should'
|
||||
import * as q from '../dist/index'
|
||||
|
||||
describe('smartq', function() {
|
||||
it('should return a Deferred for .defer()', function(done) {
|
||||
let myDeferred = q.defer()
|
||||
myDeferred.promise.then(() => {
|
||||
done()
|
||||
})
|
||||
myDeferred.resolve()
|
||||
})
|
||||
|
||||
it('should let types flow through the Promise', function(done) {
|
||||
let myString = 'someString'
|
||||
let myDeferred = q.defer<string>()
|
||||
myDeferred.promise.then(x => {
|
||||
should(x).equal('someString')
|
||||
done()
|
||||
})
|
||||
myDeferred.resolve(myString)
|
||||
})
|
||||
})
|
30
ts/index.ts
Normal file
30
ts/index.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import 'typings-global'
|
||||
|
||||
export interface IResolve<T> {
|
||||
(value?: T | Promise<T>): void
|
||||
}
|
||||
|
||||
export interface IReject {
|
||||
(reason?: any): void
|
||||
}
|
||||
|
||||
export class Deferred<T> {
|
||||
promise: Promise<T>
|
||||
resolve: IResolve<T>
|
||||
reject: IReject
|
||||
constructor() {
|
||||
this.promise = new Promise<T>((resolve, reject) => {
|
||||
this.resolve = resolve
|
||||
this.reject = reject
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export let defer = <T>() => {
|
||||
return new Deferred<T>()
|
||||
}
|
||||
|
||||
|
||||
export let all = () => {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user