@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Function sleep

    • Sleeps for the given number of milliseconds.

      给定毫秒数睡眠。

      Parameters

      • ms: number

        The number of milliseconds to sleep. 睡眠的毫秒数

      • options: SleepOptions = {}

        The options for the sleep. 睡眠的配置项

        • signal

          The signal to abort the sleep. 睡眠的中止信号

      Returns Promise<void>

      A promise that resolves after the specified delay. 在指定延迟后解析的Promise

      If the sleep is aborted via the signal. 如果通过信号中止睡眠

      console.log('Start');
      await sleep(1000); // Delays execution for 1 second
      console.log('End');
      const controller = new AbortController();
      const { signal } = controller;

      setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
      try {
      await sleep(100, { signal });
      } catch (error) {
      console.error(error); // Will log 'AbortError'
      }