Class RuntimeUtils

Constructors

Properties

awaitOrTimeout: <T>(promise: Promise<T>, timeout: number) => Promise<T> = awaitOrTimeout

Wait for a promise to resolve, but only for a specified amount of time

Type declaration

    • <T>(promise: Promise<T>, timeout: number): Promise<T>
    • Type Parameters

      • T

      Parameters

      • promise: Promise<T>

        The promise to wait for

      • timeout: number

        The maximum time to wait, in milliseconds

      Returns Promise<T>

      A promise that resolves when the input promise resolves

An error if the promise does not resolve within the timeout

Any error the promise may natively throw

safeSetAsyncInterval: (
    intervalMs: number,
    fn: () => Promise<void>,
    onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
) => Timeout = safeSetAsyncInterval

Safely schedule an async interval, even if the duration is too large. Same as safeSetInterval, but async promises are awaited, after which the next interval is scheduled

Type declaration

    • (
          intervalMs: number,
          fn: () => Promise<void>,
          onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
      ): Timeout
    • Parameters

      • intervalMs: number

        The interval to wait between each call

      • fn: () => Promise<void>

        The async function to run after each interval

      • OptionalonNewTimeout: (timeout: Timeout, isTimeoutForRunFn: boolean) => void

        A callback for when a new timeout is scheduled

      Returns Timeout

      The interval object

An error if the interval value is negative

safeSetInterval: (
    intervalMs: number,
    fn: () => void,
    onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
) => Timeout = safeSetInterval

Safely schedule an interval, even if the duration is too large. Uses safeSetTimeout to recursively schedule timeouts

Type declaration

    • (
          intervalMs: number,
          fn: () => void,
          onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
      ): Timeout
    • Parameters

      • intervalMs: number

        The interval to wait between each call

      • fn: () => void

        The function to run after each interval

      • OptionalonNewTimeout: (timeout: Timeout, isTimeoutForRunFn: boolean) => void

        A callback for when a new timeout is scheduled

      Returns Timeout

      The interval object

An error if the interval value is negative

safeSetTimeout: (
    timeoutMs: number,
    scheduleOverflowInFuture: boolean,
    fn: () => void,
    onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
) => Timeout = safeSetTimeout

Safely schedule a timeout, even if the duration is too large

Type declaration

    • (
          timeoutMs: number,
          scheduleOverflowInFuture: boolean,
          fn: () => void,
          onNewTimeout?: (timeout: Timeout, isTimeoutForRunFn: boolean) => void,
      ): Timeout
    • Parameters

      • timeoutMs: number

        The number of milliseconds to wait

      • scheduleOverflowInFuture: boolean

        Whether to schedule the overflow in the future

      • fn: () => void

        The function to run after the timeout

      • OptionalonNewTimeout: (timeout: Timeout, isTimeoutForRunFn: boolean) => void

        A callback for when a new timeout is scheduled

      Returns Timeout

      The timeout object

An error if the timeout value is negative

An error if the timeout value is too large for an int32, and scheduleOverflowInFuture is false

sleep: (ms: number) => Promise<unknown> = sleep

Sleep/wait for a specified amount of time

Type declaration

    • (ms: number): Promise<unknown>
    • Parameters

      • ms: number

        The number of milliseconds to sleep

      Returns Promise<unknown>

      A promise that resolves after specified time

sleepUntil: (
    condition: () => boolean | Promise<boolean>,
    interval?: number,
) => Promise<void> = sleepUntil

Sleep until a condition is met

Type declaration

    • (condition: () => boolean | Promise<boolean>, interval?: number): Promise<void>
    • Parameters

      • condition: () => boolean | Promise<boolean>

        The condition to wait for

      • interval: number = UnitConstants.MS_IN_ONE_SECOND

        The interval to check the condition, in milliseconds

      Returns Promise<void>

      A promise that resolves when the condition is met/true

sleepUntilOrTimeout: (
    condition: () => boolean | Promise<boolean>,
    timeout: number,
    interval?: number,
) => Promise<void> = sleepUntilOrTimeout

Sleep until a condition is met or a timeout is reached

Type declaration

    • (
          condition: () => boolean | Promise<boolean>,
          timeout: number,
          interval?: number,
      ): Promise<void>
    • Parameters

      • condition: () => boolean | Promise<boolean>

        The condition to wait for

      • timeout: number

        The maximum time to wait, in milliseconds

      • interval: number = UnitConstants.MS_IN_ONE_SECOND

        The interval to check the condition, in milliseconds

      Returns Promise<void>

      A promise that resolves when the condition is met/true