awaitDispose()function
awaitDispose(...values: Nullish<AsyncDisposable | Disposable | Callback | Promise<unknown>>[]): Promise<void>
| Param | Type | |
|---|---|---|
values | Nullish<AsyncDisposableDisposableCallbackPromise<unknown>>[] | Zero or more (possibly async) disposables, promises, or callbacks. - Note that spec says [Symbol.dispose] is called on an object if [Symbol.asyncDispose] is not found.- Promises and Callback are allowed because in real usage [Symbol.asyncDispose] may have other things to clean up too and it's neater to throw a single aggregate error.- Nullish values are skipped (for convenience). required |
| Return | |
|---|---|
Promise<void> |
| Throws | |
|---|---|
Errors | Error that aggregates all the disposal errors. |
Safely dispose one or more AsyncDisposable or Disposable values in parallel — all are disposed even if some throw, errors are rethrown at the end.
@todo Potentially rewrite this to use AsyncDisposableStack internally.
Examples
await awaitDispose(asyncResource, promise, () => cleanup()) // disposes all in parallel