method TaskClass.try
Private
TaskClass.try<T, A extends unknown[]>(
fn: (...args: A) => T | PromiseLike<T>,
...args: A
): TaskClass<Awaited<T>>

The call boundary with arguments — Promise.try's shape, made lazy: fn(...args) runs on first await, and whatever it throws (sync or async) becomes the rejection. The closure the caller would otherwise write by hand (Task(() => fn(a, b))) is built here instead.

const runGit = async (args: string[], cwd: string) => `ran git ${args[0]} in ${cwd}`;

const scan = Task.try(runGit, ['status', '--porcelain'], '.'); // lazy, args captured
await scan.retry(2); // three fresh runGit executions at most

Type Parameters

A extends unknown[]

Parameters

fn: (...args: A) => T | PromiseLike<T>
...args: A

Return Type

TaskClass<Awaited<T>>

Usage

import { TaskClass } from "lib/task/task.ts";