ExtendableEvent.waitUntil()
method tells the event dispatcher that work is ongoing. It can also be used to detect whether that work was successful. In service workers,
waitUntil()
tells the browser that work is ongoing until the promise settles, and it shouldn't terminate the service worker if it wants that work to complete.
安装
events in
service workers
使用
waitUntil()
to hold the service worker in the
installing
phase until tasks complete. If the promise passed to
waitUntil()
rejects, the install is considered a failure, and the installing service worker is discarded. This is primarily used to ensure that a service worker is not considered installed until all of the core caches it depends on are successfully populated.
activate
events in
service workers
使用
waitUntil()
to buffer functional events such as
fetch
and
push
until the promise passed to
waitUntil()
settles. This gives the service worker time to update database schemas and delete outdated
caches
, so other events can rely on a completely upgraded state.
waitUntil()
method must be initially called within the event callback, but after that it can be called multiple times, until all the promises passed to it settle.
注意 : The behaviour described in the above paragraph was fixed in Firefox 43 (see bug 1180274 ).
extendableEvent.waitUntil(promise);
A
Promise
.
使用
waitUntil()
within a service worker's
安装
event:
addEventListener('install', event => {
const preCache = async () => {
const cache = await caches.open('static-v1');
return cache.addAll([
'/',
'/about/',
'/static/styles.css'
]);
};
event.waitUntil(preCache());
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'waitUntil()' in that specification. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
waitUntil
|
Chrome 40 | Edge 17 | Firefox 44 | IE No | Opera 24 | Safari No | WebView Android 40 | Chrome Android 40 | Firefox Android 44 | Opera Android 24 | Safari iOS No | Samsung Internet Android 4.0 |
异步
waitUntil
|
Chrome ? | Edge 17 | Firefox 53 | IE No | Opera ? | Safari No | WebView Android ? | Chrome Android ? | Firefox Android 53 | Opera Android ? | Safari iOS No | Samsung Internet Android ? |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
ExtendableEvent
waitUntil()