Skip to content

Commit 6bb67cf

Browse files
committed
fix(@opentelemetry/exporter-collector): remove fulfilled promises correctly
1 parent a2304c9 commit 6bb67cf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporterBrowserBase.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ export abstract class CollectorExporterBrowserBase<
6868
const serviceRequest = this.convert(items);
6969
const body = JSON.stringify(serviceRequest);
7070

71-
const promise = new Promise(resolve => {
71+
const promise = new Promise<void>((resolve) => {
7272
const _onSuccess = (): void => {
7373
onSuccess();
74-
_onFinish();
74+
resolve();
7575
};
7676
const _onError = (error: collectorTypes.CollectorExporterError): void => {
7777
onError(error);
78-
_onFinish();
79-
};
80-
const _onFinish = () => {
8178
resolve();
82-
const index = this._sendingPromises.indexOf(promise);
83-
this._sendingPromises.splice(index, 1);
8479
};
8580

8681
if (this._useXHR) {
@@ -97,5 +92,10 @@ export abstract class CollectorExporterBrowserBase<
9792
}
9893
});
9994
this._sendingPromises.push(promise);
95+
const _onFinish = () => {
96+
const index = this._sendingPromises.indexOf(promise);
97+
this._sendingPromises.splice(index, 1);
98+
};
99+
promise.then(_onFinish);
100100
}
101101
}

0 commit comments

Comments
 (0)