Skip to content

tap()

Perform side effects without changing the result.

Syntax

typescript
task.tap(fn: (value: T) => void | Promise<void>): FuturableTask<T>

Parameters

fn

Function to execute for side effects. Return value is ignored.

Return Value

A new FuturableTask<T> with the same result value.

Examples

Logging

typescript
const task = FuturableTask
  .of(() => fetchData())
  .tap(data => console.log('Received:', data))
  .map(data => processData(data));

Progress Tracking

typescript
const task = FuturableTask
  .of(() => readFile())
  .tap(() => updateProgress(33))
  .map(data => parseData(data))
  .tap(() => updateProgress(66))
  .map(parsed => transformData(parsed))
  .tap(() => updateProgress(100));

Caching

typescript
const task = FuturableTask
  .fetch('/api/data')
  .map(res => res.json())
  .tap(data => cache.set('key', data))
  .map(data => data.items);

Analytics

typescript
const task = FuturableTask
  .of(() => performAction())
  .tap(result => analytics.track('action_completed', result));

See Also

Released under the MIT License.