add onPerform callback to collapsedQueue
This commit is contained in:
parent
fceb0d0d50
commit
e52ff9208e
1 changed files with 4 additions and 2 deletions
|
|
@ -23,7 +23,8 @@ export class CollapsedQueue<K, V> {
|
|||
private readonly collapse: (oldValue: V, newValue: V) => V,
|
||||
private readonly perform: (key: K, value: V) => Promise<void | unknown>,
|
||||
private readonly opts?: {
|
||||
onError?: (queue: CollapsedQueue<K, V>, error: unknown) => void,
|
||||
onError?: (queue: CollapsedQueue<K, V>, error: unknown) => void | Promise<void>,
|
||||
onPerform?: (queue: CollapsedQueue<K, V>, key: K, value: V) => void | Promise<void>,
|
||||
concurrency?: number,
|
||||
},
|
||||
) {
|
||||
|
|
@ -73,8 +74,9 @@ export class CollapsedQueue<K, V> {
|
|||
} else {
|
||||
await this.perform(key, value);
|
||||
}
|
||||
await this.opts?.onPerform?.(this, key, value);
|
||||
} catch (err) {
|
||||
this.opts?.onError?.(this, err);
|
||||
await this.opts?.onError?.(this, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue