* 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)
| 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') { |
no test coverage detected