Reputation: 41
I was looking for an easier way to work with WebWorker
i found 3 npm packages that worked for my case:
I am wondering the performance between these packages because i need to exchange hundreds of data (text
or ArrayBuffer
) per second between main thread and webworker so i need these communication quite fast.
Please help me!
Note: I read the document of @fcanvas/communicate
and I decided to use more MessageChannel
like this
worker.ts
import { listen } from "@fcanvas/communicate"
listen(self, "send port", (port: MessagePort) => {
port.start()
listen(port, "sort_db", () => {
// ...
})
// ...
})
main.ts
import Worker from "./worker.ts?worker"
import { put } from "@fcanvas/communicate"
function createWorker() {
const { port1, port2 } = new MessageChannel()
const worker = new Worker()
await put(worker, "send port", port2)
port1.start()
// put
}
I expected a fast and easy method for worker and thread communication
Upvotes: 4
Views: 170