gpt4 book ai didi

deno - 童工如何向 Deno 中的父进程发送消息?

转载 作者:行者123 更新时间:2023-12-04 09:46:11 27 4
gpt4 key购买 nike

来自 this answer ,我知道父进程可以与童工对话,但反过来呢?

最佳答案

从你必须使用的 worker Worker.postMessage

self.postMessage('hi')

在主进程中:

const worker = new Worker("./worker.js", { type: "module", deno: true });

worker.addEventListener('message', message => {
console.log('message', message);
// message.data === 'hi'
});

关于 self

The Window.self read-only property returns the window itself, as a WindowProxy. It can be used with dot notation on a window object (that is, window.self) or standalone (self). The advantage of the standalone notation is that a similar notation exists for non-window contexts, such as in Web Workers. By using self, you can refer to the global scope in a way that will work not only in a window context (self will resolve to window.self) but also in a worker context (self will then resolve to WorkerGlobalScope.self).

关于deno - 童工如何向 Deno 中的父进程发送消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62096840/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com