* Push a message to the queue with a mode.
(message: string, mode: T, localId?: string)
| 40 | * Push a message to the queue with a mode. |
| 41 | */ |
| 42 | push(message: string, mode: T, localId?: string): void { |
| 43 | if (this.closed) { |
| 44 | throw new Error('Cannot push to closed queue'); |
| 45 | } |
| 46 | |
| 47 | const modeHash = this.modeHasher(mode); |
| 48 | logger.debug(`[MessageQueue2] push() called with mode hash: ${modeHash}`); |
| 49 | |
| 50 | this.queue.push({ |
| 51 | message, |
| 52 | mode, |
| 53 | modeHash, |
| 54 | localId, |
| 55 | isolate: false |
| 56 | }); |
| 57 | |
| 58 | // Trigger message handler if set |
| 59 | if (this.onMessageHandler) { |
| 60 | this.onMessageHandler(message, mode); |
| 61 | } |
| 62 | |
| 63 | // Notify waiter if any |
| 64 | if (this.waiter) { |
| 65 | logger.debug(`[MessageQueue2] Notifying waiter`); |
| 66 | const waiter = this.waiter; |
| 67 | this.waiter = null; |
| 68 | waiter(true); |
| 69 | } |
| 70 | |
| 71 | logger.debug(`[MessageQueue2] push() completed. Queue size: ${this.queue.length}`); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Push a message immediately without batching delay. |