* Push a message to the beginning of the queue with a mode.
(message: string, mode: T, localId?: string)
| 188 | * Push a message to the beginning of the queue with a mode. |
| 189 | */ |
| 190 | unshift(message: string, mode: T, localId?: string): void { |
| 191 | if (this.closed) { |
| 192 | throw new Error('Cannot unshift to closed queue'); |
| 193 | } |
| 194 | |
| 195 | const modeHash = this.modeHasher(mode); |
| 196 | logger.debug(`[MessageQueue2] unshift() called with mode hash: ${modeHash}`); |
| 197 | |
| 198 | this.queue.unshift({ |
| 199 | message, |
| 200 | mode, |
| 201 | modeHash, |
| 202 | localId, |
| 203 | isolate: false |
| 204 | }); |
| 205 | |
| 206 | // Trigger message handler if set |
| 207 | if (this.onMessageHandler) { |
| 208 | this.onMessageHandler(message, mode); |
| 209 | } |
| 210 | |
| 211 | // Notify waiter if any |
| 212 | if (this.waiter) { |
| 213 | logger.debug(`[MessageQueue2] Notifying waiter`); |
| 214 | const waiter = this.waiter; |
| 215 | this.waiter = null; |
| 216 | waiter(true); |
| 217 | } |
| 218 | |
| 219 | logger.debug(`[MessageQueue2] unshift() completed. Queue size: ${this.queue.length}`); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Push a message to the beginning of the queue with isolation preserved. |
no test coverage detected