n8n/packages/core/src/DeferredPromise.ts
2019-06-23 12:35:23 +02:00

15 lines
476 B
TypeScript

// From: https://gist.github.com/compulim/8b49b0a744a3eeb2205e2b9506201e50
export interface IDeferredPromise<T> {
promise: () => Promise<T>;
reject: (error: Error) => void;
resolve: (result: T) => void;
}
export function createDeferredPromise<T>(): Promise<IDeferredPromise<T>> {
return new Promise<IDeferredPromise<T>>(resolveCreate => {
const promise = new Promise<T>((resolve, reject) => {
resolveCreate({ promise: () => promise, resolve, reject });
});
});
}