UNPKG

2.02 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = pTimeout;
7
8var global = (function () {
9 if (typeof globalThis !== 'undefined') {
10 return globalThis;
11 } else if (typeof global !== 'undefined') {
12 return global;
13 } else if (typeof self !== 'undefined') {
14 return self;
15 } else if (typeof window !== 'undefined') {
16 return window;
17 } else {
18 return Function('return this')();
19 }
20})();
21
22var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
23
24var global = (function () {
25 if (typeof globalThis !== 'undefined') {
26 return globalThis;
27 } else if (typeof global !== 'undefined') {
28 return global;
29 } else if (typeof self !== 'undefined') {
30 return self;
31 } else if (typeof window !== 'undefined') {
32 return window;
33 } else {
34 return Function('return this')();
35 }
36})();
37
38var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
39
40var global = (function () {
41 if (typeof globalThis !== 'undefined') {
42 return globalThis;
43 } else if (typeof global !== 'undefined') {
44 return global;
45 } else if (typeof self !== 'undefined') {
46 return self;
47 } else if (typeof window !== 'undefined') {
48 return window;
49 } else {
50 return Function('return this')();
51 }
52})();
53
54var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
55
56/**
57 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
58 *
59 * This source code is licensed under the MIT license found in the
60 * LICENSE file in the root directory of this source tree.
61 */
62// A specialized version of `p-timeout` that does not touch globals.
63// It does not throw on timeout.
64function pTimeout(promise, ms, clearTimeout, setTimeout, onTimeout) {
65 return new Promise((resolve, reject) => {
66 const timer = setTimeout(() => resolve(onTimeout()), ms);
67 promise.then(
68 val => {
69 clearTimeout(timer);
70 resolve(val);
71 },
72 err => {
73 clearTimeout(timer);
74 reject(err);
75 }
76 );
77 });
78}