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 Feb 23, 2021
1 parent 9a67045 commit 81fb7a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
Expand Up @@ -58,22 +58,21 @@ export abstract class CollectorExporterNodeBase<
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);
};

this._send(this, objects, _onSuccess, _onError);
});

this._sendingPromises.push(promise);
promise.then(() => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
}

onInit(config: CollectorExporterConfigNode): void {
Expand Down
Expand Up @@ -39,22 +39,20 @@ export abstract class CollectorExporterNodeBase<
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);
};

this._send(this, objects, _onSuccess, _onError);
});

this._sendingPromises.push(promise);
promise.then(() => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
}

onInit(config: CollectorExporterNodeConfigBase): void {
Expand Down
Expand Up @@ -72,16 +72,11 @@ export abstract class CollectorExporterBrowserBase<
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 @@ -91,5 +86,9 @@ export abstract class CollectorExporterBrowserBase<
}
});
this._sendingPromises.push(promise);
promise.then(() => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
}
}
Expand Up @@ -65,16 +65,11 @@ export abstract class CollectorExporterNodeBase<
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);
};
sendWithHttp(
this,
Expand All @@ -84,8 +79,11 @@ export abstract class CollectorExporterNodeBase<
_onError
);
});

this._sendingPromises.push(promise);
promise.then(() => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
}

onShutdown(): void {}
Expand Down
6 changes: 4 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Expand Up @@ -76,11 +76,13 @@ export class ZipkinExporter implements SpanExporter {
this._sendSpans(spans, this._serviceName!, result => {
resolve();
resultCallback(result);
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
});
this._sendingPromises.push(promise);
promise.then(() => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
});
}

/**
Expand Down

0 comments on commit 81fb7a6

Please sign in to comment.