Skip to content

FuturableTask.resolve() ​

Create a task that immediately resolves with a value.

Syntax ​

typescript
FuturableTask.resolve<T>(value: T): FuturableTask<T>

Parameters ​

value ​

The value to resolve with.

Return Value ​

A FuturableTask<T> that resolves with the provided value.

Description ​

Creates a task that immediately succeeds with the given value when executed. Useful for starting task chains or providing default values.

Examples ​

Basic Usage ​

typescript
const task = FuturableTask.resolve(42);
const result = await task.run(); // 42

Starting a Chain ​

typescript
const task = FuturableTask
  .resolve([1, 2, 3, 4, 5])
  .map(arr => arr.filter(x => x > 2))
  .map(arr => arr.map(x => x * 2));

const result = await task.run(); // [6, 8, 10]

Conditional Tasks ​

typescript
const task = condition
  ? FuturableTask.resolve(cachedData)
  : FuturableTask.fetch('/api/data').map(r => r.json());

Default Values ​

typescript
const getData = (useCache: boolean) =>
  useCache
    ? FuturableTask.resolve(CACHED_VALUE)
    : FuturableTask.of(() => fetchFreshData());

Testing ​

typescript
// Mock async operations in tests
const mockFetch = FuturableTask.resolve({
  id: 1,
  name: 'Test User'
});

See Also ​

Released under the MIT License.