React Hookers - v6.3.0
    Preparing search index...

    Function useLock

    • Promise-based lock implementation.

      When someone tries to acquire the lock using acquire, they receive a promise for a release callback. The promise is fulfilled as soon as the previous lock owner invokes their release callback. If acquire is called after the component is unmounted, the returned promise is never fulfilled.

      Returns [isLocked: boolean, acquire: () => Promise<() => void>]

      const [isLocked, acquire] = useLock();

      async function doSomething() {
      const release = await acquire();
      try {
      // Long process starts here
      } finally {
      release();
      }
      }

      // The long process will be executed three times sequentially
      doSomething();
      doSomething();
      doSomething();