{
  "version": 3,
  "sources": ["../../../src/binding-utils/lock-utils.ts"],
  "sourcesContent": ["import type { ReadonlyBinding } from '../binding/types/readonly-binding';\nimport { makeValueThenDo } from './internal/make-value-then-do.mjs';\n\n/**\n * Checks if any of the specified bindings have been locked.\n *\n * @param bindings - The bindings to check\n *\n * @returns `true` if any of the specified bindings are locked, `false` otherwise.\n */\nexport const areAnyBindingsLocked = (bindings: Array<ReadonlyBinding | undefined>) => {\n  for (const binding of bindings) {\n    if (binding?.isLocked() ?? false) {\n      return true;\n    }\n  }\n\n  return false;\n};\n\n/**\n * Locks all the specified bindings and returns a function for unlocking them in reverse order.\n *\n * @param bindings - The bindings to be locked\n *\n * @returns a function to unlock all of the specified bindings, in reverse order\n */\nexport const lockAllBindings = (bindings: Array<ReadonlyBinding | undefined>) => {\n  const unlockers = bindings.map((binding) => binding?.lock()).reverse();\n\n  return () => {\n    for (const unlock of unlockers) {\n      unlock?.();\n    }\n  };\n};\n\n/**\n * Locks the specified bindings until the functions result is resolved or rejected\n *\n * @param bindings - The bindings to be locked\n * @param func - The function to run while the bindings are locked\n *\n * @returns The result of the specified function\n */\nexport const lockBindingsAndDo = <T>(bindings: Array<ReadonlyBinding | undefined>, func: () => Promise<T> | T): Promise<T> | T => {\n  const unlockAllBindings = lockAllBindings(bindings);\n\n  return makeValueThenDo(func, unlockAllBindings);\n};\n"],
  "mappings": "AACA,SAAS,uBAAuB;AASzB,MAAM,uBAAuB,CAAC,aAAiD;AACpF,aAAW,WAAW,UAAU;AAC9B,QAAI,SAAS,SAAS,KAAK,OAAO;AAChC,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AASO,MAAM,kBAAkB,CAAC,aAAiD;AAC/E,QAAM,YAAY,SAAS,IAAI,CAAC,YAAY,SAAS,KAAK,CAAC,EAAE,QAAQ;AAErE,SAAO,MAAM;AACX,eAAW,UAAU,WAAW;AAC9B,eAAS;AAAA,IACX;AAAA,EACF;AACF;AAUO,MAAM,oBAAoB,CAAI,UAA8C,SAA+C;AAChI,QAAM,oBAAoB,gBAAgB,QAAQ;AAElD,SAAO,gBAAgB,MAAM,iBAAiB;AAChD;",
  "names": []
}
