function strategy()

in workbox-v4.3.1/workbox-streams.dev.js [272:319]


  function strategy(sourceFunctions, headersInit) {
    return async ({
      event,
      url,
      params
    }) => {
      if (isSupported()) {
        const {
          done,
          response
        } = concatenateToResponse(sourceFunctions.map(fn => fn({
          event,
          url,
          params
        })), headersInit);
        event.waitUntil(done);
        return response;
      }

      {
        logger_mjs.logger.log(`The current browser doesn't support creating response ` + `streams. Falling back to non-streaming response instead.`);
      } // Fallback to waiting for everything to finish, and concatenating the
      // responses.


      const parts = await Promise.all(sourceFunctions.map(sourceFunction => sourceFunction({
        event,
        url,
        params
      })).map(async responsePromise => {
        const response = await responsePromise;

        if (response instanceof Response) {
          return response.blob();
        } // Otherwise, assume it's something like a string which can be used
        // as-is when constructing the final composite blob.


        return response;
      }));
      const headers = createHeaders(headersInit); // Constructing a new Response from a Blob source is well-supported.
      // So is constructing a new Blob from multiple source Blobs or strings.

      return new Response(new Blob(parts), {
        headers
      });
    };
  }