diff --git a/README.md b/README.md index d815ada..0da96cf 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,25 @@ Async collection is an utility to collect needed keys and signalize on done. - `options.exact?: boolean` - `options.timeout?: number` - `options.reassign?: boolean` + - `options.defaults?: object` + - `options.validate?: (data: Record) => unknown` - `set(key: string, value: unknown)` - `wait(key: string, fn: AsyncFunction | Promise, ...args?: Array)` - `take(key: string, fn: Function, ...args?: Array)` - `collect(sources: Record)` - `fail(error: Error)` -- `then(fulfill: Function, reject?: Function)` +- `abort()` +- `then(onFulfill: Function, onReject?: Function)` - `done: boolean` - `data: Dictionary` - `keys: Array` - `count: number` - `exact: boolean` - `timeout: number` +- `defaults: object` +- `reassign: boolean` +- `validate?: (data: Record) => unknown` +- `signal: AbortSignal` Collect keys with `.set` method: @@ -84,6 +91,17 @@ ac.take('user', getUserCallback, 'Marcus'); const result = await ac; ``` +Set default values ​​for unset keys using the `options.defaults` argument: + +```js +const defaults = { key1: 'sub1', key2: 'sub1' }; + +const dc = collect(['key1', 'key2'], { defaults, timeout: 2000 }); +dc.set('key2', 'sub2'); + +const result = await dc; +``` + Compose collectors (collect subkeys from multiple sources): ```js