Skip to content

Commit

Permalink
fix(@opentelemetry/exporter-collector): remove fulfilled promises cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
aabmass committed Dec 22, 2020
1 parent a2304c9 commit 6bb67cf
Showing 1 changed file with 7 additions and 7 deletions.
Expand Up @@ -68,19 +68,14 @@ export abstract class CollectorExporterBrowserBase<
const serviceRequest = this.convert(items);
const body = JSON.stringify(serviceRequest);

const promise = new Promise(resolve => {
const promise = new Promise<void>((resolve) => {
const _onSuccess = (): void => {
onSuccess();
_onFinish();
resolve();
};
const _onError = (error: collectorTypes.CollectorExporterError): void => {
onError(error);
_onFinish();
};
const _onFinish = () => {
resolve();
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
};

if (this._useXHR) {
Expand All @@ -97,5 +92,10 @@ export abstract class CollectorExporterBrowserBase<
}
});
this._sendingPromises.push(promise);
const _onFinish = () => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
};
promise.then(_onFinish);
}
}

0 comments on commit 6bb67cf

Please sign in to comment.