MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / transactionSink

Function transactionSink

packages/deno/test/deno-http.test.ts:27–55  ·  view source on GitHub ↗

* `beforeSendTransaction` hook plus a `waitFor(predicate)` helper * resolves when a matching transaction arrives (or has already arrived)

()

Source from the content-addressed store, hash-verified

25 * resolves when a matching transaction arrives (or has already arrived)
26 */
27function transactionSink(): {
28 transactions: TransactionEvent[];
29 beforeSendTransaction: (event: TransactionEvent) => null;
30 waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise<TransactionEvent>;
31} {
32 const transactions: TransactionEvent[] = [];
33 const waiters: { predicate: (e: TransactionEvent) => boolean; resolve: (e: TransactionEvent) => void }[] = [];
34 return {
35 transactions,
36 beforeSendTransaction(event) {
37 transactions.push(event);
38 for (let i = waiters.length - 1; i >= 0; i--) {
39 const w = waiters[i]!;
40 if (w.predicate(event)) {
41 waiters.splice(i, 1);
42 w.resolve(event);
43 }
44 }
45 return null;
46 },
47 waitFor(predicate) {
48 const already = transactions.find(predicate);
49 if (already) return Promise.resolve(already);
50 return new Promise<TransactionEvent>(resolve => {
51 waiters.push({ predicate, resolve });
52 });
53 },
54 };
55}
56
57// Bind a promise so a real "never arrives" bug fails the test.
58function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T> {

Callers 1

fnFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected