appolo-utils
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -55,4 +55,37 @@ "use strict"; | ||
} | ||
static fromCallback(resolver) { | ||
return new Promise((resolve, reject) => { | ||
resolver((err, data) => { | ||
if (err !== null) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
} | ||
static defer() { | ||
return new Deferred(); | ||
} | ||
} | ||
exports.Promises = Promises; | ||
class Deferred { | ||
constructor() { | ||
this._promise = new Promise((resolve, reject) => { | ||
this._resolveSelf = resolve; | ||
this._rejectSelf = reject; | ||
}); | ||
} | ||
get promise() { | ||
return this._promise; | ||
} | ||
resolve(val) { | ||
this._resolveSelf(val); | ||
} | ||
reject(reason) { | ||
this._rejectSelf(reason); | ||
} | ||
} | ||
exports.Deferred = Deferred; | ||
//# sourceMappingURL=promises.js.map |
@@ -13,3 +13,3 @@ type Resolvable<R> = R | PromiseLike<R> | ||
let params = {index:0}, results = [], iterator = iterable[Symbol.iterator](), promises = []; | ||
let params = {index: 0}, results = [], iterator = iterable[Symbol.iterator](), promises = []; | ||
@@ -50,3 +50,3 @@ while (concurrency-- > 0) { | ||
let params = {index:0}, results = [], predicates = [], iterator = iterable[Symbol.iterator](), promises = []; | ||
let params = {index: 0}, results = [], predicates = [], iterator = iterable[Symbol.iterator](), promises = []; | ||
@@ -83,2 +83,46 @@ while (concurrency-- > 0) { | ||
} | ||
public static fromCallback<T>(resolver: (callback: (err: any, result?: T) => void) => void): Promise<T> { | ||
return new Promise((resolve, reject) => { | ||
resolver((err, data) => { | ||
if (err !== null) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}) | ||
}) | ||
} | ||
private static defer<T>(): Deferred<T> { | ||
return new Deferred(); | ||
} | ||
} | ||
export class Deferred<T> { | ||
private _resolveSelf; | ||
private _rejectSelf; | ||
private readonly _promise: Promise<T>; | ||
constructor() { | ||
this._promise = new Promise((resolve, reject) => { | ||
this._resolveSelf = resolve; | ||
this._rejectSelf = reject; | ||
}) | ||
} | ||
public get promise(): Promise<T> { | ||
return this._promise; | ||
} | ||
public resolve(val: T): void { | ||
this._resolveSelf(val) | ||
} | ||
public reject(reason: any): void { | ||
this._rejectSelf(reason) | ||
} | ||
} |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49140
940