Function fromFunction

  • Lift from sync function to task resolving to said function result

    Generally, functions are not considered tasks as they cannot be interrupted in any way However there may be cases when impure function performs actions leading to cancelling or failing the task they are called from Without such wrapper such cases would lead to ignoring said cancelation and continuilg task chain This function is mostly used internally and is not expected to be widely used except of some edge scenarios

    If converted task is canceled or failed externally return value will be ignored without side-effects All tasks are no-trowing by default, any occured errors are returned as Left

    Type Parameters

    • R

      returned task resolve type

    Parameters

    • producer: (() => R)

      function to be wrapped to a task

        • (): R
        • Returns R

    • cancelRef: {
          cancel: TaskCancel;
      }

      reference object allowing to set cancelation function prior to invoking function

      • cancel: TaskCancel

    Returns Task<R>

    task resolving to the specified function's result

    Example

    const cancelRef = { cancel: () => {} };

    const task = Task.fromFunction(() => someFunction('someData'), cancelRef).map((result) => result.length);

Generated using TypeDoc