@common.js/p-timeout 6.1.1 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [p-timeout](https://www.npmjs.com/package/p-timeout) package exported as CommonJS modules.
4
4
 
5
- Exported from [p-timeout@6.1.1](https://www.npmjs.com/package/p-timeout/v/6.1.1) using https://github.com/etienne-martin/common.js.
5
+ Exported from [p-timeout@6.1.2](https://www.npmjs.com/package/p-timeout/v/6.1.2) using https://github.com/etienne-martin/common.js.
package/index.d.ts CHANGED
@@ -3,12 +3,12 @@ export class TimeoutError extends Error {
3
3
  constructor(message?: string);
4
4
  }
5
5
 
6
- export interface ClearablePromise<T> extends Promise<T> {
6
+ export type ClearablePromise<T> = {
7
7
  /**
8
8
  Clear the timeout.
9
9
  */
10
10
  clear: () => void;
11
- }
11
+ } & Promise<T>;
12
12
 
13
13
  export type Options<ReturnType> = {
14
14
  /**
package/index.js CHANGED
@@ -322,14 +322,10 @@ function pTimeout(promise, options) {
322
322
  clearTimeout: clearTimeout
323
323
  } : _customTimers;
324
324
  var timer;
325
- var cancelablePromise = new Promise(function(resolve, reject) {
325
+ var wrappedPromise = new Promise(function(resolve, reject) {
326
326
  if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
327
327
  throw new TypeError("Expected `milliseconds` to be a positive number, got `".concat(milliseconds, "`"));
328
328
  }
329
- if (milliseconds === Number.POSITIVE_INFINITY) {
330
- resolve(promise);
331
- return;
332
- }
333
329
  if (options.signal) {
334
330
  var signal = options.signal;
335
331
  if (signal.aborted) {
@@ -339,6 +335,10 @@ function pTimeout(promise, options) {
339
335
  reject(getAbortedReason(signal));
340
336
  });
341
337
  }
338
+ if (milliseconds === Number.POSITIVE_INFINITY) {
339
+ promise.then(resolve, reject);
340
+ return;
341
+ }
342
342
  // We create the error outside of `setTimeout` to preserve the stack trace.
343
343
  var timeoutError = new TimeoutError();
344
344
  timer = customTimers.setTimeout.call(undefined, function() {
@@ -370,8 +370,8 @@ function pTimeout(promise, options) {
370
370
  _state.trys.push([
371
371
  0,
372
372
  2,
373
- 3,
374
- 4
373
+ ,
374
+ 3
375
375
  ]);
376
376
  return [
377
377
  4,
@@ -383,21 +383,16 @@ function pTimeout(promise, options) {
383
383
  ]);
384
384
  return [
385
385
  3,
386
- 4
386
+ 3
387
387
  ];
388
388
  case 2:
389
389
  error = _state.sent();
390
390
  reject(error);
391
391
  return [
392
392
  3,
393
- 4
393
+ 3
394
394
  ];
395
395
  case 3:
396
- customTimers.clearTimeout.call(undefined, timer);
397
- return [
398
- 7
399
- ];
400
- case 4:
401
396
  return [
402
397
  2
403
398
  ];
@@ -405,6 +400,9 @@ function pTimeout(promise, options) {
405
400
  });
406
401
  })();
407
402
  });
403
+ var cancelablePromise = wrappedPromise.finally(function() {
404
+ cancelablePromise.clear();
405
+ });
408
406
  cancelablePromise.clear = function() {
409
407
  customTimers.clearTimeout.call(undefined, timer);
410
408
  timer = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common.js/p-timeout",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "description": "p-timeout package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
@@ -24,7 +24,7 @@
24
24
  "p-cancelable": "^4.0.1",
25
25
  "time-span": "^5.1.0",
26
26
  "tsd": "^0.22.0",
27
- "xo": "^0.51.0"
27
+ "xo": "^0.54.2"
28
28
  },
29
29
  "homepage": "https://github.com/etienne-martin/common.js#readme",
30
30
  "dependencies": {},