Closing one fossil sketch preview cancels rendering in other windows
Level 3 · node · Concurrency · Subscriber cancellation disagrees with the lifetime of a shared asynchronous task
Scenario
A fictional fossil exhibition studio renders sketch previews by name using an in-memory rendering device. Windows requesting the same sketch share one in-progress task. Closing a window should cancel only its own request, but other windows waiting for the same sketch sometimes receive no image. Trace the public request entry point, shared-task layer, and device completion and cancellation flows together.
Requirements
createStudio() exposes request(name), complete(name, image), and stats(). request returns a result Promise and a cancel function. Start only one in-progress render per name and allow each request to be cancelled independently. A cancelled request receives { status: 'cancelled' }; a request that waits for completion receives { status: 'ready', image }. Cancel the device task only when its last waiting request is cancelled; the next request must start a new task. Repeated cancellation of a cancelled or completed request must not affect other tasks. Tasks for different names are independent. Preserve the public interface.
Acceptance criteria
- Concurrent requests for the same name render once and deliver the result to every waiting request.
- Cancelling only some requests allows the remaining and newly joining requests to receive the same render result.
- Cancelling the last waiting request stops the task exactly once, and the next request for that name starts a new task.
- Tasks for different names and repeated cancellation of completed requests do not affect each other.