From the course: JavaScript: Web Workers

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Update progress and import scripts

Update progress and import scripts - JavaScript Tutorial

From the course: JavaScript: Web Workers

Start my 1-month free trial

Update progress and import scripts

- [Instructor] Continuing with our project, we have already sent the final output to the main thread. The next step is to also send the progress status. Because every time we move to a new country, we want to have the progress bar. So for that we are also going to post a message, in this case it will be a different message, with a different action. We can call this progress, and the data that we want to send, like a payload, that we want to send, it's exactly this thing. So now, I need to remove that, go to process.js, and we can add another case for our messaging protocol. It's going to be "progress," and now, we can reuse that query selector that we had, and we also want to use event dot data, that's the object coming from the other thread, and then we have that object, and another data property. Now we can go and try this. If I hit start, we have an error. It says the distance is not defined. And why is that? Our algorithm was relying on the distance property. That property is in…

Contents