File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 33import { assert } from "@std/assert/assert" ;
44import { exists } from "@std/fs/exists" ;
55import { BuildOptions , context } from "esbuild" ;
6+ import { AsyncDisposableStack } from "../misc/async_disposable_stack.ts" ;
67import { OPTIONS } from "./config.ts" ;
78
89const BUILD_OPTIONS : BuildOptions = {
Original file line number Diff line number Diff line change 22
33import { unreachable } from "@std/assert/unreachable" ;
44import { debounce } from "@std/async/debounce" ;
5+ import { AsyncDisposableStack } from "../misc/async_disposable_stack.ts" ;
56import { build } from "./build.ts" ;
67
78async function tryBuild ( ) : Promise < void > {
Original file line number Diff line number Diff line change 1+ // This code is Deno only
2+
3+ // TODO: remove this after Deno supports it
4+ export class AsyncDisposableStack implements AsyncDisposable {
5+ #callbacks: Array < ( ) => Promise < void > > = [ ] ;
6+ defer ( onDisposeAsync : ( ) => Promise < void > ) : void {
7+ this . #callbacks. push ( onDisposeAsync ) ;
8+ }
9+ move ( ) : AsyncDisposableStack {
10+ const newStack = new AsyncDisposableStack ( ) ;
11+ newStack . #callbacks = this . #callbacks;
12+ this . #callbacks = [ ] ;
13+ return newStack ;
14+ }
15+ async [ Symbol . asyncDispose ] ( ) : Promise < void > {
16+ const errors = [ ] ;
17+ for ( const callback of this . #callbacks. reverse ( ) ) {
18+ try {
19+ await callback ( ) ;
20+ } catch ( error ) {
21+ errors . push ( error ) ;
22+ }
23+ }
24+ switch ( errors . length ) {
25+ case 0 :
26+ break ;
27+ case 1 :
28+ throw errors [ 0 ] ;
29+ default :
30+ throw AggregateError ( errors ) ;
31+ }
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments