demo/service_worker.js
function timeout(seconds, asyncProcess) {
  return Promise.race([
    asyncProcess,
    new Promise(function(_, reject) {
      setTimeout(reject, seconds * 1000);
    }),
  ]);
}
function timeout(seconds, asyncProcess) {
  return Promise.race([
    asyncProcess,
    new Promise(function(_, reject) {
      setTimeout(reject, seconds * 1000);
    }),
  ]);
}
function timeout ( seconds , asyncProcess ) { return Promise . race ( [ asyncProcess , new Promise ( function ( _ , reject ) { setTimeout ( reject , seconds * 1000 ) ; } ) , ] ) ; }
Returns a Promise which is resolved only if |asyncProcess| is resolved, and
only if it is resolved in less than |seconds| seconds.

If the returned Promise is resolved, it returns the same value as
|asyncProcess|.

If |asyncProcess| fails, the returned Promise is rejected.
If |asyncProcess| takes too long, the returned Promise is rejected, but
|asyncProcess| is still allowed to complete.

@param {number} seconds
@param {!Promise.<T>} asyncProcess
@return {!Promise.<T>}
@template T
Returns a Promise which is resolved only if |asyncProcess| is resolved and only if it is resolved in less than |seconds| seconds .