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 3
3
import { assert } from "@std/assert/assert" ;
4
4
import { exists } from "@std/fs/exists" ;
5
5
import { BuildOptions , context } from "esbuild" ;
6
+ import { AsyncDisposableStack } from "../misc/async_disposable_stack.ts" ;
6
7
import { OPTIONS } from "./config.ts" ;
7
8
8
9
const BUILD_OPTIONS : BuildOptions = {
Original file line number Diff line number Diff line change 2
2
3
3
import { unreachable } from "@std/assert/unreachable" ;
4
4
import { debounce } from "@std/async/debounce" ;
5
+ import { AsyncDisposableStack } from "../misc/async_disposable_stack.ts" ;
5
6
import { build } from "./build.ts" ;
6
7
7
8
async 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