File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,13 @@ import { MACHINE_METADATA } from "./constants.js";
7
7
import { EventCache } from "./eventCache.js" ;
8
8
import { detectContainerEnv } from "../helpers/container.js" ;
9
9
import type { DeviceId } from "../helpers/deviceId.js" ;
10
- import { EventEmitter } from "stream " ;
10
+ import { EventEmitter } from "events " ;
11
11
12
12
type EventResult = {
13
13
success : boolean ;
14
14
error ?: Error ;
15
15
} ;
16
16
17
- async function timeout ( promise : Promise < unknown > , ms : number ) : Promise < void > {
18
- await Promise . race ( [ new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) , promise ] ) ;
19
- }
20
-
21
17
export interface TelemetryEvents {
22
18
"events-emitted" : [ ] ;
23
19
"events-send-failed" : [ ] ;
@@ -90,7 +86,9 @@ export class Telemetry {
90
86
91
87
public async close ( ) : Promise < void > {
92
88
this . isBufferingEvents = false ;
93
- await timeout ( this . emit ( [ ] ) , 5_000 ) ;
89
+
90
+ // Wait up to 5 seconds for events to be sent before closing, but don't throw if it times out
91
+ await Promise . race ( [ new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) , this . emit ( [ ] ) ] ) ;
94
92
}
95
93
96
94
/**
You can’t perform that action at this time.
0 commit comments