export function createRequestLock() {
  let active = false;
  return {
    pending: () => active,
    run(operation) {
      if (active) return undefined;
      active = true;
      let result;
      try {
        result = operation();
      } catch (error) {
        active = false;
        throw error;
      }
      return Promise.resolve(result).finally(() => { active = false; });
    }
  };
}
