Skip to content

Commit af2a186

Browse files
author
ranrib
committed
feat(main): first version
1 parent d167323 commit af2a186

File tree

4 files changed

+43
-43
lines changed

4 files changed

+43
-43
lines changed

package-lock.json

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/promises.js

-23
This file was deleted.

src/tracer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ class RequestTracer extends Span {
286286
return sampleRates[key] || 1;
287287
}
288288
}
289-
exports.RequestTracer = RequestTracer;
289+
export default RequestTracer;

src/wrapper.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1-
const promises1 = require('./promises');
2-
const tracer1 = require('./tracer');
1+
import RequestTracer from './tracer';
2+
3+
class PromiseSettledCoordinator {
4+
constructor(finished) {
5+
this.finished = finished;
6+
this.promises = [];
7+
this.allSettled = false;
8+
}
9+
10+
addPromise(promise) {
11+
if (this.allSettled) {
12+
throw Error('All promises have already been settled!');
13+
}
14+
this.promises.push(promise);
15+
const currentLength = this.promises.length;
16+
const settled = Promise.allSettled(this.promises);
17+
settled.then((results) => {
18+
if (currentLength === this.promises.length) {
19+
this.allSettled = true;
20+
this.finished(results);
21+
}
22+
});
23+
}
24+
}
25+
exports.PromiseSettledCoordinator = PromiseSettledCoordinator;
326

427
class TraceWrapper {
528
constructor(event, listener, config) {
629
this.event = event;
730
this.listener = listener;
831
this.waitUntilUsed = false;
932
this.config = config;
10-
this.tracer = new tracer1.RequestTracer(event.request, this.config);
33+
this.tracer = new RequestTracer(event.request, this.config);
1134
this.waitUntilSpan = this.tracer.startChildSpan('waitUntil', 'worker');
12-
this.settler = new promises1.PromiseSettledCoordinator(() => {
35+
this.settler = new PromiseSettledCoordinator(() => {
1336
this.waitUntilSpan.finish();
1437
this.sendEvents();
1538
});

0 commit comments

Comments
 (0)