File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 11import { constants } from "os" ;
22
33import { END_FLUSH_TIMEOUT_MS } from "./config" ;
4+ import { withTimeout , TimeoutError } from "./utils" ;
45
56type Callback = ( ) => Promise < void > ;
67
@@ -20,21 +21,18 @@ export function subscribe(
2021 state = false ;
2122
2223 try {
23- const result = await Promise . race ( [
24- new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( true ) , timeout ) ) ,
25- callback ( ) ,
26- ] ) ;
27-
28- if ( result === true ) {
24+ await withTimeout ( callback ( ) , timeout ) ;
25+ } catch ( error ) {
26+ if ( error instanceof TimeoutError ) {
2927 console . error (
3028 "[Bucket SDK] Timeout while flushing events on process exit." ,
3129 ) ;
30+ } else {
31+ console . error (
32+ "[Bucket SDK] An error occurred while flushing events on process exit." ,
33+ error ,
34+ ) ;
3235 }
33- } catch ( error ) {
34- console . error (
35- "[Bucket SDK] An error occurred while flushing events on process exit." ,
36- error ,
37- ) ;
3836 }
3937
4038 state = true ;
You can’t perform that action at this time.
0 commit comments