@nevware21/ts-utils
    Preparing search index...

    Function scheduleNextTick

    • Schedules a callback to run using process.nextTick when available and otherwise uses an Promise-based fallback before using the timer-backed queue.

      When scheduleFn is provided, it is used before the Promise and timer-backed fallbacks. When useTimeout is true, the timer-backed queue is used instead of the Promise fallback. maxQueuedTasks controls the fallback queue depth limit; when omitted the Promise/timer fallback queues use a Node-compatible default of 1000. Set maxQueuedTasks to 0 to disable the limit (for fallbacks only, the native process.nextTick is not affected by this limit).

      Parameters

      • callback: MicrotaskFn

        The callback to execute.

      • Optionaloptions: NextTickOptions

        Optional fallback behavior when native process.nextTick is not available.

      Returns ITimerHandler

      A handler that can be used to cancel or refresh the scheduled callback.

      0.15.0

      scheduleNextTick(() => {
      console.log("nextTick callback");
      });

      scheduleNextTick(() => {
      console.log("timer-backed nextTick");
      }, {
      useTimeout: true
      });

      scheduleNextTick(() => {
      console.log("custom nextTick fallback");
      }, {
      scheduleFn: (cb) => {
      setTimeout(cb, 0);
      }
      });
      // Args only
      scheduleNextTick((name: string, count: number) => {
      console.log(name, count);
      }, ["task", 1]);

      // Args + options
      scheduleNextTick((name: string, count: number) => {
      console.log(name, count);
      }, ["task", 2], {
      useTimeout: true
      });
    • Schedules a callback to run using process.nextTick when available and otherwise uses an Promise-based fallback before using the timer-backed queue.

      When scheduleFn is provided, it is used before the Promise and timer-backed fallbacks. When useTimeout is true, the timer-backed queue is used instead of the Promise fallback. maxQueuedTasks controls the fallback queue depth limit; when omitted the Promise/timer fallback queues use a Node-compatible default of 1000. Set maxQueuedTasks to 0 to disable the limit (for fallbacks only, the native process.nextTick is not affected by this limit).

      Type Parameters

      • TArgs extends any[]

      Parameters

      • callback: (...args: TArgs) => void

        The callback to execute.

      • args: TArgs

        Optional callback arguments to pass when the callback executes.

      • Optionaloptions: NextTickOptions

        Optional fallback behavior when native process.nextTick is not available.

      Returns ITimerHandler

      A handler that can be used to cancel or refresh the scheduled callback.

      0.15.0

      scheduleNextTick(() => {
      console.log("nextTick callback");
      });

      scheduleNextTick(() => {
      console.log("timer-backed nextTick");
      }, {
      useTimeout: true
      });

      scheduleNextTick(() => {
      console.log("custom nextTick fallback");
      }, {
      scheduleFn: (cb) => {
      setTimeout(cb, 0);
      }
      });
      // Args only
      scheduleNextTick((name: string, count: number) => {
      console.log(name, count);
      }, ["task", 1]);

      // Args + options
      scheduleNextTick((name: string, count: number) => {
      console.log(name, count);
      }, ["task", 2], {
      useTimeout: true
      });