MCPcopy Create free account
hub / github.com/tiann/hapi / unshift

Method unshift

cli/src/utils/MessageQueue2.ts:190–220  ·  view source on GitHub ↗

* Push a message to the beginning of the queue with a mode.

(message: string, mode: T, localId?: string)

Source from the content-addressed store, hash-verified

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.

Callers 9

unshiftIsolatedMethod · 0.80
killProcessWindowsFunction · 0.80
createCursorAcpBackendFunction · 0.80
listRunnerLogFilesFunction · 0.80
PermissionHandlerClass · 0.80

Calls 1

debugMethod · 0.80

Tested by

no test coverage detected