n8n/packages/workflow/src/DeferredPromise.ts
Tomi Turtiainen 9a1cc56806
fix: Set '@typescript-eslint/return-await' rule to 'always' for node code (no-changelog) (#8363)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2024-01-17 17:08:50 +02:00

15 lines
509 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 async function createDeferredPromise<T = void>(): Promise<IDeferredPromise<T>> {
return await new Promise<IDeferredPromise<T>>((resolveCreate) => {
const promise = new Promise<T>((resolve, reject) => {
resolveCreate({ promise: async () => await promise, resolve, reject });
});
});
}