async-manager-promise
Advanced tools
Comparing version 0.0.4 to 0.0.5
import AsyncManager from 'async-manager'; | ||
const errCbToPromiseExecutor = (resolve, reject) => (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(data); | ||
} | ||
}; | ||
class AsyncManagerPromise { | ||
@@ -8,10 +16,4 @@ constructor() { | ||
const promise = new Promise(async (resolve, reject) => { | ||
this.manager.add(id, (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(data); | ||
} | ||
}); | ||
const cb = errCbToPromiseExecutor(resolve, reject); | ||
this.manager.add(id, cb); | ||
}); | ||
@@ -21,4 +23,5 @@ return promise; | ||
getPromiseWithId(onInit) { | ||
const promise = new Promise(async (resolve) => { | ||
const id = this.manager.addAndGetId(resolve); | ||
const promise = new Promise(async (resolve, reject) => { | ||
const cb = errCbToPromiseExecutor(resolve, reject); | ||
const id = this.manager.addAndGetId(cb); | ||
if (onInit) { | ||
@@ -25,0 +28,0 @@ onInit(id); |
{ | ||
"name": "async-manager-promise", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "TODO", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
import AsyncManager from 'async-manager' | ||
const errCbToPromiseExecutor = (resolve, reject) => | ||
(err, data) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(data) | ||
} | ||
} | ||
class AsyncManagerPromise<OutputType, Id = any> { | ||
@@ -8,9 +17,4 @@ protected manager = new AsyncManager<OutputType, Id>() | ||
const promise = new Promise<OutputType>(async (resolve, reject) => { | ||
this.manager.add(id, (err, data) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(data) | ||
} | ||
}) | ||
const cb = errCbToPromiseExecutor(resolve, reject) | ||
this.manager.add(id, cb) | ||
}) | ||
@@ -22,4 +26,6 @@ | ||
getPromiseWithId(onInit?: (id: string) => void) { | ||
const promise = new Promise<OutputType>(async (resolve) => { | ||
const id = this.manager.addAndGetId(resolve) | ||
const promise = new Promise<OutputType>(async (resolve, reject) => { | ||
const cb = errCbToPromiseExecutor(resolve, reject) | ||
const id = this.manager.addAndGetId(cb) | ||
if (onInit) { | ||
@@ -26,0 +32,0 @@ onInit(id) |
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
5864
112