Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Does ExtendableEvent.waitUntil() has any timeout or can be aborted?

The service worker install event is given an instance of ExtendableEvent to its handler which you can use it to pause registration by calling waitUntil() method and pass a promise. e.g.

// inside service worker
self.addEventListener('install', function(event) {
    ...
    event.waitUntil(promise1);
    console.log("waiting for promise1");
});

My question is that, is there any way to cancel the wait after some time or that SW registration remains indefinitely in the " trying to install" phase as long as that promise is not resolved or rejected. Since I didn't see any timeout or abort option with waitUntil method.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, a nit: InstallEvent's waitUntil() method does not pause registration. Service worker registration is distinct from the execution of the install phase of the registered service worker. (There is more background in this answer.)

If you call waitUntil() inside of an install event handler, the service worker won't progress out of the installing state until either the promise resolves, or until a browser-specific timeout is reached, at which point I believe the promise will be treated as if it rejected. This timeout is not part of the service worker specification and can vary from browser to browser, so I would not rely on it being set to any specific value.

It sounds like you'd like to impose your own deterministic timeout with a hard limit on how long users might have to wait. If that's the case, you can do that by creating a new Promise and inside of that, combining your original async operation with a call to setTimeout().

const TIMEOUT_MS = ...;

self.addEventListener('install', (event) => {
  const originalPromise = ...;

  const promiseWithTimeout = new Promise((resolve, reject) => {
    const id = setTimeout(
      () => reject(new Error(`Timed out after ${TIMEOUT_MS}ms`)),
      TIMEOUT_MS,
    );

    originalPromise.then((result) => {
      clearTimeout(id);
      resolve(result);
    }).catch((err) => reject(err));
  });

  event.waitUntil(promiseWithTimeout);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!