add_task(async function async_wait_until() { var worker;
let registration = await navigator.serviceWorker.register( "async_waituntil_worker.js", { scope: "./"} )
.then(function(reg) {
worker = reg.installing;
return waitForState(worker, 'activated', reg);
});
// The service worker will claim us when it becomes active.
ok(navigator.serviceWorker.controller, "Controlled");
// This will make the service worker die immediately if there are no pending
// waitUntil promises to keep it alive.
await SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.idle_timeout", 0],
["dom.serviceWorkers.idle_extended_timeout", 299999]]});
// The service worker will wait on two promises, one of which
// will be rejected. We check whether the SW is killed using
// the value of a global variable.
let waitForStart = wait_for_message("Started");
worker.postMessage("Start");
await waitForStart;
await new Promise((res, rej) => {
setTimeout(res, 0);
});
let waitResult = wait_for_message("Success");
worker.postMessage("Result");
await waitResult;
// Test the behaviour of calling waitUntil asynchronously. The important
// part is that we receive the message event.
let waitForMessage = wait_for_message("Done");
await fetch("doesnt_exist.html").then(() => {
ok(true, "Fetch was successful.");
});
await waitForMessage;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.