How to use the workbox-core/_private/Deferred.js.Deferred function in workbox-core

To help you get started, we’ve selected a few workbox-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChrome / workbox / packages / workbox-streams / src / concatenate.ts View on Github external
} {
  if (process.env.NODE_ENV !== 'production') {
    assert!.isArray(sourcePromises, {
      moduleName: 'workbox-streams',
      funcName: 'concatenate',
      paramName: 'sourcePromises',
    });
  }

  const readerPromises = sourcePromises.map((sourcePromise) => {
    return Promise.resolve(sourcePromise).then((source) => {
      return _getReaderFromSource(source);
    });
  });

  const streamDeferred:Deferred = new Deferred();

  let i = 0;
  const logMessages: any[] = [];
  const stream = new ReadableStream({
    pull(controller: ReadableStreamDefaultController) {
      return readerPromises[i]
          .then((reader) => reader.read())
          .then((result) => {
            if (result.done) {
              if (process.env.NODE_ENV !== 'production') {
                logMessages.push(['Reached the end of source:',
                  sourcePromises[i]]);
              }

              i++;
              if (i >= readerPromises.length) {