See deno-redis.test.ts — same sink shape, deduped for clarity.
()
| 17 | |
| 18 | /** See deno-redis.test.ts — same sink shape, deduped for clarity. */ |
| 19 | function transactionSink(): { |
| 20 | beforeSendTransaction: (event: TransactionEvent) => null; |
| 21 | waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise<TransactionEvent>; |
| 22 | } { |
| 23 | const transactions: TransactionEvent[] = []; |
| 24 | const waiters: { predicate: (e: TransactionEvent) => boolean; resolve: (e: TransactionEvent) => void }[] = []; |
| 25 | return { |
| 26 | beforeSendTransaction(event) { |
| 27 | transactions.push(event); |
| 28 | for (let i = waiters.length - 1; i >= 0; i--) { |
| 29 | const w = waiters[i]!; |
| 30 | if (w.predicate(event)) { |
| 31 | waiters.splice(i, 1); |
| 32 | w.resolve(event); |
| 33 | } |
| 34 | } |
| 35 | return null; |
| 36 | }, |
| 37 | waitFor(predicate) { |
| 38 | const already = transactions.find(predicate); |
| 39 | if (already) return Promise.resolve(already); |
| 40 | return new Promise<TransactionEvent>(resolve => { |
| 41 | waiters.push({ predicate, resolve }); |
| 42 | }); |
| 43 | }, |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T> { |
| 48 | let timer: ReturnType<typeof setTimeout> | undefined; |
no outgoing calls
no test coverage detected