codemelted.js Module
    Preparing search index...

    Function async_task

    • Will execute an asynchronous task and get its result in the future.

      Type Parameters

      • T

        The data to be processed through the CFuture.

      Parameters

      • params: { data: T; delay?: number; task: CTaskCB<T> }

        The named parameters.

        • data: T

          The optional data to pass to the task.

        • Optionaldelay?: number

          The delay to schedule the task in the future. Defaults to 0 if not specified.

        • task: CTaskCB<T>

          The task to run.

      Returns CFuture<T>

      An object to execute the asynchronous task. You can also re-execute the future by calling the CFuture.execute method.

      // Schedule a task for getting a future result and write it to the
      // console.
      let future = async_task({
      task: (data) => { return data + 20; },
      data: 22,
      delay: 1000,
      execute: true,
      });
      let result = await future.result();
      console.log("result = ", result.value());