Skip to content

Commit

Permalink
doc: elaborate on confusing Node-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Apr 24, 2024
1 parent 0351b6d commit 2deb898
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions agents/src/ipc/job_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ if (process.send) {
const start = () => {
if (room.isConnected && !closed) {
process.send!({ type: IPC_MESSAGE.StartJobResponse });

// JavaScript doesn't let us pass down function arguments to children /as functions/,
// because the [Function] type is a class, and thus is incompatible with the Web Workers
// structured clone algorithm, which only allows simple types and object literals.
// attempting to pass a function here through IPC will lead to a runtime DataCloneError.
//
// further info:
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
new Function('return ' + process.argv[3])()(new JobContext(closeEvent, args.job!, room));
}
};
Expand Down

0 comments on commit 2deb898

Please sign in to comment.