1 | export type AsyncDebugBlock = () => unknown;
|
2 | export type DebugConsume = (debugLog: AsyncDebugBlock) => void;
|
3 |
|
4 | export interface DebugHandler {
|
5 | debug: DebugConsume;
|
6 | }
|
7 |
|
8 | export class BufferedDebugHandler implements DebugHandler {
|
9 | private buffer: Array<AsyncDebugBlock>;
|
10 | constructor() {
|
11 | this.buffer = [];
|
12 | }
|
13 |
|
14 | debug(debugMsg: AsyncDebugBlock): void {
|
15 | this.buffer.push(debugMsg);
|
16 | }
|
17 |
|
18 | executeBufferedBlocks(): Array<unknown> {
|
19 | const logs = this.buffer.map((block) => block());
|
20 | this.buffer = [];
|
21 | return logs;
|
22 | }
|
23 | }
|