campfire.js
    Preparing search index...

    Function callbackify

    • Converts a function that returns a Promise into a function that accepts a Node-style callback.

      This utility helps integrate Promise-based code with callback-based APIs, including using async operations in synchronous contexts like Store event handlers.

      Type Parameters

      • T extends any[]

        The types of the function arguments

      • U = unknown

        The type of the value that the Promise resolves to (default: unknown)

      • E = any

        The type of the error that might be caught (default: any)

      Parameters

      • fn: (...args: T) => Promise<U>

        A function that returns a Promise

      Returns Callbackified<T, U, E>

      A function that accepts a Node-style callback as its first argument

      // Using with Store event handlers (which expect synchronous functions)
      // Instead of this (which uses async in a non-async context):
      myStore.on('update', async (event) => {
      const data = await fetchDataFromApi(event.value);
      // Do something with data...
      });

      // Do this instead:
      const handleUpdateAsync = async (event) => {
      const data = await fetchDataFromApi(event.value);
      // Do something with data...
      };

      myStore.on('update', (event) => {
      callbackify(handleUpdateAsync)(
      (err, _) => { if (err) console.error('Error:', err); },
      event
      );
      });