diff --git a/abstract-relay.ts b/abstract-relay.ts index e76d521..1a8d920 100644 --- a/abstract-relay.ts +++ b/abstract-relay.ts @@ -102,12 +102,7 @@ export class AbstractRelay { this._connected = false } - this.ws.onmessage = ev => { - this.incomingMessageQueue.enqueue(ev.data as string) - if (!this.queueRunning) { - this.runQueue() - } - } + this.ws.onmessage = this._onmessage }) return this.connectionPromise @@ -268,10 +263,10 @@ export class AbstractRelay { this.ws?.close() } - // this method simulates receiving a message from the websocket - // for testing purposes only - public _push(msg: string) { - this.incomingMessageQueue.enqueue(msg) + // this is the function assigned to this.ws.onmessage + // it's exposed for testing and debugging purposes + public _onmessage(ev: MessageEvent) { + this.incomingMessageQueue.enqueue(ev.data as string) if (!this.queueRunning) { this.runQueue() } diff --git a/benchmark.ts b/benchmark.ts index fb855f8..4b645e0 100644 --- a/benchmark.ts +++ b/benchmark.ts @@ -46,7 +46,7 @@ const runWith = (relay: AbstractRelay) => async () => { }, }) for (let e = 0; e < messages.length; e++) { - relay._push(messages[e]) + relay._onmessage({ data: messages[e] } as any) } }) }