New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send a message from vue-worker like worker.onmessage #14
Comments
I'd like to know the answer too! This module is pointless to me if I can't communicate back. Perhaps if we pass in a computed field? But I think we send copies, not shared variables, so I don't think we can update computed fields. Can we use Vuex? I'll probably try that. |
+1 yeah this module is almost useless if you can't communicate from the Worker during processing. To be fair, the Web Worker concept is structurally outdated and incompatible with the modern web application development process. I can see why hardly anyone uses it! |
If anyone comes across this issue... You actually can just bypass this entire myWebWorker.js const worker = () => {
let i = 0
setInterval(function () {
i++
// Sending data to Main
postMessage(i) // sent data to main app
}, 500)
// Receiving data from Main
onmessage = (event) => {
console.log(`From main> ${event.data}`)
}
}
export const myWebWorker = new Blob([`(${worker.toString()})()`], {
type: 'text/javascript',
}) main.js import { myWebWorker } from './myWebWorker.js'
if (typeof Worker !== undefined) {
window.URL = window.URL || window.webkitURL // polyfill
// Register the web worker
const worker = new Worker(
window.URL.createObjectURL(myWebWorker),
)
// Receiving data from the Worker
worker.onmessage = function (e) {
console.log(`From worker> ${e.data}`)
}
// Example of sending data from Main to Worker
setTimeout(() => {
worker.postMessage('hello')
}, 5000)
} |
I have that code:
I want to put it in vue worker. Every day, when the time is 8am or 8pm i want to toggle a boolean variable within a component.
Using just workers that would be possible by:
But i can't figure out how to do this using vue-worker
The text was updated successfully, but these errors were encountered: