waitUntil.js 587 B

12345678910111213141516171819202122
  1. /*
  2. Copyright 2020 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. /**
  9. * A utility method that makes it easier to use `event.waitUntil` with
  10. * async functions and return the result.
  11. *
  12. * @param {ExtendableEvent} event
  13. * @param {Function} asyncFn
  14. * @return {Function}
  15. * @private
  16. */
  17. function waitUntil(event, asyncFn) {
  18. const returnPromise = asyncFn();
  19. event.waitUntil(returnPromise);
  20. return returnPromise;
  21. }
  22. export { waitUntil };