tryError Documentation

Function: withProgress()
Function

```ts function withProgress<T>(fn, options?): ProgressTracker<T>; ``` Defined in: [async.ts:581](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/async.ts#L581) Create an async operation with progress tracking

tryError API Documentation v0.0.1-alpha.1


tryError API Documentation / withProgress

Function: withProgress()

function withProgress<T>(fn, options?): ProgressTracker<T>;

Defined in: async.ts:581

Create an async operation with progress tracking

Type Parameters

T

T

Parameters

fn

(setProgress) => Promise<T>

Async function that receives a progress callback

options?

TryAsyncOptions

Optional configuration

Returns

ProgressTracker<T>

ProgressTracker with promise and progress methods

Example

const tracker = withProgress(async (setProgress) => {
  setProgress(0);
  await processChunk1();
  setProgress(33);
  await processChunk2();
  setProgress(66);
  await processChunk3();
  setProgress(100);
  return result;
});

// Check progress
const interval = setInterval(() => {
  console.log(`Progress: ${tracker.getProgress()}%`);
}, 1000);

const result = await tracker.promise;
clearInterval(interval);