campfire.js
    Preparing search index...

    Function poll

    • Repeatedly executes a function at specified intervals.

      This utility provides a continuous polling mechanism with proper cleanup. The function always schedules the next execution even if the current one throws an error.

      Parameters

      • fn: () => void

        The function to execute repeatedly

      • interval: number

        Time in milliseconds between each execution

      • callNow: boolean = false

        Whether to execute the function immediately (default: false)

      Returns () => void

      A cancel function that stops the polling when called

      // Check for updates every 5 seconds
      const stopPolling = poll(() => {
      checkForNewMessages();
      }, 5000, true); // Start immediately

      // Later, when you want to stop polling:
      stopPolling();