| 839 | }, |
| 840 | |
| 841 | pollEvents(): Promise<BackendEventBatch> { |
| 842 | if (disposed) return Promise.reject(new Error("NodeBackend: disposed")); |
| 843 | if (fatal !== null) return Promise.reject(fatal); |
| 844 | if (stopRequested) return Promise.reject(new Error("NodeBackend: stopped")); |
| 845 | |
| 846 | const queued = eventQueue.shift(); |
| 847 | if (queued !== undefined) { |
| 848 | const buf = queued.batch; |
| 849 | const bytes = new Uint8Array(buf, 0, queued.byteLen); |
| 850 | let released = false; |
| 851 | return Promise.resolve({ |
| 852 | bytes, |
| 853 | droppedBatches: queued.droppedSinceLast, |
| 854 | release: () => { |
| 855 | if (released) return; |
| 856 | released = true; |
| 857 | if (disposed) return; |
| 858 | send({ type: "eventsAck", buffer: buf }, [buf]); |
| 859 | }, |
| 860 | }); |
| 861 | } |
| 862 | |
| 863 | const d = deferred<BackendEventBatch>(); |
| 864 | eventWaiters.push(d); |
| 865 | return d.promise; |
| 866 | }, |
| 867 | |
| 868 | postUserEvent(tag: number, payload: Uint8Array): void { |
| 869 | if (disposed) throw new Error("NodeBackend: disposed"); |