Files
vercel__workflow/packages/world-postgres/src/util.ts
Gal Schlezinger 4ca9a3edbd Introducing Workflow DevKit
build durable, resilient, and observable workflows.

Co-authored-by: Nathan Rajlich <n@n8.io>
Co-authored-by: Pranay Prakash <pranay.gp@gmail.com>
Co-authored-by: Adrian <me@adriandlam.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Vercel Release Bot <88769842+vercel-release-bot@users.noreply.github.com>
Co-authored-by: Peter Wielander <mittgfu@gmail.com>
Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com>
Co-authored-by: Gal Schlezinger <gal@spitfire.co.il>
Co-authored-by: Manuel Muñoz Solera <mamuso@mamuso.net>
Co-authored-by: Garrett <garrett.tolbert@vercel.com>
Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
Co-authored-by: Tom Dale <tom@tomdale.net>
Co-authored-by: Vishal Yathish <135551666+visyat@users.noreply.github.com>
Co-authored-by: josh <144584931+dancer@users.noreply.github.com>
2025-10-23 12:07:52 +03:00

27 lines
598 B
TypeScript

export class Mutex {
promise: Promise<unknown> = Promise.resolve();
andThen<T>(fn: () => Promise<T> | T): Promise<T> {
this.promise = this.promise.then(
() => fn(),
() => fn()
);
return this.promise as Promise<T>;
}
}
export function compact<T extends object>(obj: T) {
const value = {} as {
[key in keyof T]: null extends T[key]
? undefined | NonNullable<T[key]>
: T[key];
};
for (const key in obj) {
if (obj[key] !== null) {
value[key] = obj[key] as any;
} else {
value[key] = undefined as any;
}
}
return value;
}