/** Serialize mic open/close so the second session waits for tracks to release. */
let releaseChain = Promise.resolve();

export function waitForMicRelease() {
  return releaseChain;
}

export function extendMicRelease(until: Promise<unknown>) {
  let release!: () => void;
  const gate = new Promise<void>((resolve) => {
    release = resolve;
  });
  releaseChain = releaseChain.then(() => gate);
  void until.finally(() => release());
}
