Formalizing a timeout API
Nobody has claimed this yet.
- Dominant language
- Bikeshed
- Stars
- 3.6k
- Forks
- 324
- Avg merge
- 14d 22h
- Merged PRs (30d)
- 1
Description
It looks like the idea has already been brought up and is already implemented in some fashion in at least Firefox and Chrome, but it would be nice if there was some spec guarantee on guarding async operations with a timeout, and some way to customize behavior.
In theory, it's not hard to create a service worker than can never be removed, by creating some aysnc operation that can never finish:
e.waitUntil(new Promise(() => {}));
addEventListener('install', (e) => {
e.waitUntil(registration.unregister());
});
A few ideas for public APIs to prevent these issues and provide fine-grain control:
Additional timeout param for waitUntil/respondWith
// Abort if promise doesn't resolve within 5 seconds.
e.waitUntil(new Promise(() => {}), { timeout: 5000 });
API for adding a default timeout for functional events
Not quite sure where this could be done. Perhaps during worker registration? I feel like adding a worker specific option to addEventListener would be too intrusive.
Allow installing worker to cutoff active worker
Specifically, allow skipWaiting to provide an “ultimatum” timeout to the active worker to finish any async operations.
// Give the active worker 5 seconds to terminate any operations before killing
self.skipWaiting({
gracePeriod: 5000
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked discussion in issue 980 and the implementation noted in issue 1182, then examine the existing Service Worker behavior for waitUntil, respondWith, and skipWaiting. Done would require a decided, spec-ready timeout API and defined customization and termination semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100