n8n/packages/core/src/DeferredPromise.ts

15 lines
476 B
TypeScript
Raw Normal View History

2019-06-23 03:35:23 -07:00
// 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 });
});
});
}