MCPcopy Index your code
hub / github.com/nodejs/node / makeSyncRequest

Method makeSyncRequest

lib/internal/modules/esm/hooks.js:622–648  ·  view source on GitHub ↗

* Invoke a remote method synchronously. * @param {string} method Method to invoke * @param {any[]} [transferList] Objects in `args` to be transferred * @param {any[]} args Arguments to pass to `method` * @returns {any}

(method, transferList, ...args)

Source from the content-addressed store, hash-verified

620 * @returns {any}
621 */
622 makeSyncRequest(method, transferList, ...args) {
623 this.waitForWorker();
624
625 // Pass work to the worker.
626 debug('post sync message to worker', { method, args, transferList });
627 this.#worker.postMessage({ __proto__: null, method, args }, transferList);
628
629 let response;
630 do {
631 debug('wait for sync response from worker', { method, args });
632 // Sleep until worker responds.
633 AtomicsWait(this.#lock, WORKER_TO_MAIN_THREAD_NOTIFICATION, this.#workerNotificationLastId);
634 this.#workerNotificationLastId = AtomicsLoad(this.#lock, WORKER_TO_MAIN_THREAD_NOTIFICATION);
635
636 response = this.#worker.receiveMessageSync();
637 debug('got sync message from worker', { method, args, response });
638 } while (response == null);
639
640 if (response.message.status === 'never-settle') {
641 const error = new ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED();
642 error.details = { method, args };
643 throw error;
644 } else if (response.message.status === 'exit') {
645 process.exit(response.message.body);
646 }
647 return this.#unwrapMessage(response);
648 }
649
650 #unwrapMessage(response) {
651 if (response.message.status === 'never-settle') {

Callers 3

registerMethod · 0.80
resolveSyncMethod · 0.80
loadSyncMethod · 0.80

Calls 6

waitForWorkerMethod · 0.95
#unwrapMessageMethod · 0.95
receiveMessageSyncMethod · 0.80
debugFunction · 0.50
postMessageMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected