Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

503 B
Raw Blame
/**
 * Creates a simple async mutex (promise-based lock).
 * Returns a `withLock(fn)` function that serializes async operations.
 * Uses try/finally to guarantee the lock is always released, even on error.
 */
export function createMutex() {
  let lock = Promise.resolve();
  return async function withLock(fn) {
    const release = lock;
    let resolve;
    lock = new Promise(r => { resolve = r; });
    await release;
    try {
      return await fn();
    } finally {
      resolve();
    }
  };
}