What does event.waitUntil do in service worker and why is it needed? : <p>MDN suggests that you do the following to create and populate service worker cache:</p>

<pre><code>this.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open('v1').then(function(cache) {
      return cache.addAll([
        '/sw-test/',
        '/sw-test/index.html',
        ... etc ...
      ]);
    })
  );
});
</code></pre>

<p>I do not understand that code. The <code>waitUntil</code> method is documented too, and it seems the code above is the single purpose of it's existence at the moment:</p>

<blockquote>
  <p>The ExtendableEvent.waitUntil() method extends the lifetime of the
  event. When called in an EventHandler associated to the install event,
  it delays treating the installing worker as installed until the passed
  Promise resolves successfully. This is primarily used to ensure that a
  service worker is not considered installed until all of the core
  caches it depends on are populated.</p>
</blockquote>

<p>What I do not understand is:</p>

<ul>
<li>How does <code>waitUntil</code> generally affect code flow? Does it stop event from propagating until it's promise resolves?</li>
<li>Why is it needed in the context of opening worker cache?</li>
</ul>

<p>I am asking this question because I have problems with the code above and I would like to understand it.</p>
