1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = pTimeout;
|
7 |
|
8 | var 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 |
|
22 | var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
23 |
|
24 | var 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 |
|
38 | var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
39 |
|
40 | var 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 |
|
54 | var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function 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 | }
|