Pause, Resume, and Cancel: Designing a Batch Download Queue in a Chrome Extension A developer working on ExtMax, an Instagram media downloader for Chrome, described a cooperative pause/resume/cancel design for a batch download queue that uses a monotonically increasing cancellationVersion (epoch) captured at task start, so stale callbacks from cancelled sessions cannot advance the save path after a new job begins. The implementation checks control state before requesting a page and again after the response, awaits each page's downloads before fetching the next, and pauses only at file boundaries, since fetches carry no cancellation signal and in-flight requests may still complete. Imagine a batch task saving a page of media. One video is still transferring when someone clicks Pause. A moment later, they click Cancel and start another task. The old request finally resolves. Should it save a file, update the new progress bar, or quietly stop? This article was prepared with AI assistance and checked against a local source snapshot. The diagrams are AI-generated conceptual illustrations. This walkthrough uses the batch-download implementation in ExtMax, an instagram downloader https://extmax.com for Chrome, as a concrete example. The focus is the ordinary profile-download path that writes individual files, using accessible media the user owns or has permission to save. The reviewed source identifies itself as version 1.1.6; that does not establish which version is currently in the extension store. ZIP export, viewer batches, and incremental tracking have additional behavior. The examples below explain selected mechanisms rather than reproducing the entire extension. A control is only useful if its meaning survives an asynchronous operation. In this implementation, three responsibilities are separated: The progress service exposes pause, resume, and cancel controls, but those controls do not magically interrupt every promise. The working code must consult them. The profile loop checks a boundary before requesting a page and again after the response. That second check matters: the user may pause, cancel, or navigate while the request is pending. A valid response is not sufficient permission to start saving its contents. The task also awaits the current page's downloads before requesting the next page. This makes it easier to reason about which work has started. It is sequential within this path, not a claim that the whole extension has only one active job. The ordinary pause policy is cooperative. At a file boundary, the save session waits while the shared pause flag is set. It also waits if the selected directory is blocked. An already-acquired file may finish writing during an ordinary pause. The custom-directory writer checks cancellation between chunks, but does not stop each chunk merely because the user pressed Pause. This avoids treating a routine pause as a failed partial write. The media acquisition helper uses fetch without a task cancellation signal. Therefore, neither Pause nor Cancel should be described as immediately stopping all network traffic. A request can still finish; later checks decide whether its result may advance through the save path. That distinction belongs in the product's wording. “Hold the next item” sets a more accurate expectation than “freeze everything instantly.” A completed file appearing after a pause can be consistent with that policy. A single cancellation boolean becomes fragile when tasks overlap in time. Cancel sets it to true, a new job resets it, and an old callback wakes up after the reset. The callback can mistake the new state for permission to continue. The progress service also maintains a monotonically increasing cancellationVersion . Each save session captures the version when it starts. Cancel increments the shared value. The older session remains invalid even if a new job clears the boolean. Here is a small TypeScript model of the idea. It is an illustrative rewrite, not a drop-in source extract: class Control { epoch = 0; paused = false; pause { this.paused = true; } resume { this.paused = false; } cancel { this.epoch++; this.paused = false; } } function checkpointFor control: Control, isCurrent: = boolean { const epoch = control.epoch; const assertAlive = = { if epoch == control.epoch || isCurrent { throw new Error "TASK INVALIDATED" ; } }; return async = { assertAlive ; while control.paused { await new Promise resolve = setTimeout resolve, 250 ; assertAlive ; } assertAlive ; }; } Create the checkpoint when the task starts, not afresh for every item. Otherwise, an old task could capture a newer epoch and lose its identity. Production checks additionally cover session closure, route validity, directory blocks, and account or quota conditions. The profile's progress callbacks also check the captured version and current page before changing counts. Cancellation is a validity rule, not a rollback of files already saved. A user pause and a permission problem can both look like a stopped queue. They are not the same condition. The save session records recoverable directory problems such as lost permission or insufficient space. Resume attempts the registered checks. A failed check keeps that block in place; clearing the user-pause flag alone does not make the directory usable. The resume routine captures the cancellation version before awaiting those checks. If cancellation happens while a check is pending, the old resume attempt cannot subsequently clear the pause state of a newer run. This is also why a simple three-state diagram is only a teaching aid. The implementation uses a shared pause flag, cancellation generation, and a map of blocked tasks. It is not literally a single running | paused | cancelled enum. Those controls belong to the shared progress service in the content-script context, not an independent switch on every file. Fetching bytes and committing a file have different failure consequences. Repeating a fetch generally acquires another copy in memory. Repeating a save after a lost acknowledgement can create another file. In the reviewed downloadSingle implementation, acquisition allows one retry after a 1.5-second delay. Saving happens outside that retry loop. Some callers also stop immediately on specific access-denial responses. That policy should not be generalized to every request or download mode. This reduced example shows the separation. The supplied save function is responsible for validating the task and returning only after an appropriate save acknowledgement: js async function acquireThenSave