Skip to content

Instantly share code, notes, and snippets.

@mjy9088
mjy9088 / criticalSection.ts
Last active January 24, 2024 09:46
Typescript CriticalSection
interface Pending {
resolve: (value: any) => void;
reject: (error: any) => void;
criticalSection: () => Promise<unknown>;
}
export function criticalSection(): <T>(
criticalSection: () => Promise<T>
) => Promise<T> {
const pending: Pending[] = [];