Skip to content

Commit

Permalink
Fix: Bind postMessage (#671)
Browse files Browse the repository at this point in the history
* Bind postMessage when passing into onMessage

* Change files

* Fix
  • Loading branch information
altinokdarici authored May 30, 2023
1 parent 461581d commit 88d7269
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Bind postMessage when passing into onMessage",
"packageName": "@lage-run/scheduler",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion packages/scheduler/src/WrappedTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export class WrappedTarget implements TargetRun {
{ target },
target.weight ?? 1,
(worker, stdout, stderr) => {
const postMessage = worker.postMessage.bind(worker);

msgHandler = (data) => {
if (data.type === "log") {
logger.log(data.level, data.msg, { target, threadId: worker.threadId });
Expand All @@ -214,7 +216,7 @@ export class WrappedTarget implements TargetRun {
worker.postMessage({ type: "hash", hash });
});
} else if (this.options.onMessage) {
this.options.onMessage(data, worker.postMessage);
this.options.onMessage(data, postMessage);
}
};

Expand Down

0 comments on commit 88d7269

Please sign in to comment.