SPB Git

spb/market-atlas

Public
607 B · 19 lines typescript
1/** Minimal async mutex: serializes critical sections (multi-row upserts) so Postgres never sees two overlapping lock orders. */2export class Mutex {3  private tail: Promise<void> = Promise.resolve();45  run<T>(fn: () => Promise<T>): Promise<T> {6    const next = this.tail.then(fn, fn);7    this.tail = next.then(8      () => undefined,9      () => undefined,10    );11    return next;12  }13}1415/** One writer at a time for each hot table family. */16export const barsMutex = new Mutex();17export const quotesMutex = new Mutex();18export const masterMutex = new Mutex(); // instruments, companies, symbol_aliases19
Files · 36b2a4e714e506898a6dbfc9b2ea1ab5a3ce90b3
Menu

Theme