---
title: "Comment by Jam Yanh on \"Web Workers vs Shared Workers vs Service Workers: A Practical Guide to Choosing the Right One\" | Hashnode"
description: "The request-ID example is useful. A cancellation example would be a nice follow-up: in an image tool, a user might choose a second file while the first is still"
url: "https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5"
---

[Discussion](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc)

Comment [Web Workers vs Shared Workers vs Service Workers: A Practical Guide to Choosing the Right One](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc)

[Jam Yanh](https://hashnode.com/@danagua)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5)

The request-ID example is useful. A cancellation example would be a nice follow-up: in an image tool, a user might choose a second file while the first is still being processed. How would you stop that first job without terminating the worker and losing its other pending jobs?

[Arun kumar Velu](https://hashnode.com/@arunkumarvelu)

[Oct 8](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5#reply-6ac78cc52f2b39f099cb38b7)

a cancellation message cannot interrupt a synchronous JavaScript loop already running in that worker. The worker must divide expensive work into chunks and yield between them, giving its event loop a chance to receive the cancellation message. setTimeout() is one way to schedule the next chunk; repeatedly awaiting Promise.resolve() is not an equivalent yield to incoming message events because microtasks run before the next task.

[Jam Yanh](https://hashnode.com/@danagua)

[Oct 9](https://hashnode.com/posts/web-workers-vs-shared-workers-vs-service-workers-a-practical-guide-to-choosing-the-right-one/6ac6389bb529833a337e24dc/comment/6ac7741bfb17a98938662ab5#reply-6ac8c9505292935f39485a14)

Thanks, the distinction between yielding to a new task and only flushing microtasks is especially helpful. For an image-processing example, measuring cancellation delay alongside total processing time would make the chunk-size tradeoff easier to see.
