@@ -69,27 +69,20 @@ export abstract class CollectorExporterBrowserBase<
69
69
const serviceRequest = this . convert ( items ) ;
70
70
const body = JSON . stringify ( serviceRequest ) ;
71
71
72
- const promise = new Promise < void > ( resolve => {
73
- const _onSuccess = ( ) : void => {
74
- onSuccess ( ) ;
75
- _onFinish ( ) ;
76
- } ;
77
- const _onError = ( error : collectorTypes . CollectorExporterError ) : void => {
78
- onError ( error ) ;
79
- _onFinish ( ) ;
80
- } ;
81
- const _onFinish = ( ) => {
82
- resolve ( ) ;
83
- const index = this . _sendingPromises . indexOf ( promise ) ;
84
- this . _sendingPromises . splice ( index , 1 ) ;
85
- } ;
86
-
72
+ const promise = new Promise < void > ( ( resolve , reject ) => {
87
73
if ( this . _useXHR ) {
88
- sendWithXhr ( body , this . url , this . _headers , _onSuccess , _onError ) ;
74
+ sendWithXhr ( body , this . url , this . _headers , resolve , reject ) ;
89
75
} else {
90
- sendWithBeacon ( body , this . url , _onSuccess , _onError ) ;
76
+ sendWithBeacon ( body , this . url , resolve , reject ) ;
91
77
}
92
- } ) ;
78
+ } )
79
+ . then ( onSuccess )
80
+ . catch ( onError ) ;
81
+
93
82
this . _sendingPromises . push ( promise ) ;
83
+ promise . finally ( ( ) => {
84
+ const index = this . _sendingPromises . indexOf ( promise ) ;
85
+ this . _sendingPromises . splice ( index , 1 ) ;
86
+ } ) ;
94
87
}
95
88
}
0 commit comments