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

    Function timeout

    • Returns a promise that rejects with a TimeoutError after a specified delay.

      返回一个 promise,该 promise 在指定的延迟时间后拒绝,抛出一个 TimeoutError

      Parameters

      • ms: number

        the number of milliseconds to wait before rejecting the promise. / 超时的毫秒数

      Returns Promise<never>

      A promise that rejects with a TimeoutError after the specified delay. / 一个 promise,它将在指定的延迟时间后拒绝,抛出一个 TimeoutError

      Throws a TimeoutError after the specified delay. / 在指定的延迟时间后抛出 TimeoutError。

      try {
      await timeout(1000); // Timeout exception after 1 second
      } catch (error) {
      console.error(error); // Will log 'The operation was timed out'
      }