@@ -4,6 +4,7 @@ import type { InternalBaseTransportOptions, Transport, TransportMakeRequestRespo
44import { debug } from '../utils/debug-logger' ;
55import { envelopeContainsItemType } from '../utils/envelope' ;
66import { parseRetryAfterHeader } from '../utils/ratelimit' ;
7+ import { safeUnref } from '../utils/timer' ;
78
89export const MIN_DELAY = 100 ; // 100 ms
910export const START_DELAY = 5_000 ; // 5 seconds
@@ -97,26 +98,24 @@ export function makeOfflineTransport<TO>(
9798 clearTimeout ( flushTimer as ReturnType < typeof setTimeout > ) ;
9899 }
99100
100- flushTimer = setTimeout ( async ( ) => {
101- flushTimer = undefined ;
102-
103- const found = await store . shift ( ) ;
104- if ( found ) {
105- log ( 'Attempting to send previously queued event' ) ;
101+ // We need to unref the timer in node.js, otherwise the node process never exit.
102+ flushTimer = safeUnref (
103+ setTimeout ( async ( ) => {
104+ flushTimer = undefined ;
106105
107- // We should to update the sent_at timestamp to the current time.
108- found [ 0 ] . sent_at = new Date ( ) . toISOString ( ) ;
106+ const found = await store . shift ( ) ;
107+ if ( found ) {
108+ log ( 'Attempting to send previously queued event' ) ;
109109
110- void send ( found , true ) . catch ( e => {
111- log ( 'Failed to retry sending' , e ) ;
112- } ) ;
113- }
114- } , delay ) as Timer ;
110+ // We should to update the sent_at timestamp to the current time.
111+ found [ 0 ] . sent_at = new Date ( ) . toISOString ( ) ;
115112
116- // We need to unref the timer in node.js, otherwise the node process never exit.
117- if ( typeof flushTimer !== 'number' && flushTimer . unref ) {
118- flushTimer . unref ( ) ;
119- }
113+ void send ( found , true ) . catch ( e => {
114+ log ( 'Failed to retry sending' , e ) ;
115+ } ) ;
116+ }
117+ } , delay ) ,
118+ ) as Timer ;
120119 }
121120
122121 function flushWithBackOff ( ) : void {
0 commit comments