@flemist/test-variants 0.0.7 → 0.0.10

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.
@@ -1,32 +1,33 @@
1
1
  !function(e){"use strict"
2
2
  ;e.createTestVariants=function(e){
3
3
  return function(t){return function(n){
4
- var r=void 0===n?{}:n,o=r.pauseInterval,u=void 0===o?1e3:o,a=r.pauseTime,i=void 0===a?10:a,f=r.logInterval,c=void 0===f?1e4:f,v=Object.keys(t),l=Object.values(t),s=v.length,y={}
5
- ;function h(e){var t=l[e]
6
- ;return"function"==typeof t&&(t=t(y)),t}
7
- for(var p=[],b=[],w=0;w<s;w++)p[w]=-1,b[w]=[]
8
- ;function d(){for(var e=s-1;e>=0;e--){var t=p[e]+1
9
- ;if(t<b[e].length){
10
- for(p[e]=t,y[v[e]]=b[e][t],e++;e<s;e++){var n=h(e)
11
- ;if(0===n.length)break;p[e]=0,b[e]=n,y[v[e]]=n[0]}
12
- if(e>=s)return!0}}return!1}b[0]=h(0)
13
- ;var g=0,m=!1,j=0;function D(e){
14
- console.error(JSON.stringify(y,null,2)),console.error(e)
4
+ var o=void 0===n?{}:n,r=o.pauseInterval,u=void 0===r?1e3:r,a=o.pauseTime,i=void 0===a?10:a,f=o.logInterval,c=void 0===f?1e4:f,v=o.logCompleted,l=void 0===v||v,s=Object.keys(t),p=Object.values(t),y=s.length,g={}
5
+ ;function h(e){var t=p[e]
6
+ ;return"function"==typeof t&&(t=t(g)),t}
7
+ for(var b=[],d=[],m=0;m<y;m++)b[m]=-1,d[m]=[]
8
+ ;function w(){for(var e=y-1;e>=0;e--){var t=b[e]+1
9
+ ;if(t<d[e].length){
10
+ for(b[e]=t,g[s[e]]=d[e][t],e++;e<y;e++){var n=h(e)
11
+ ;if(0===n.length)break;b[e]=0,d[e]=n,g[s[e]]=n[0]}
12
+ if(e>=y)return!0}}return!1}d[0]=h(0)
13
+ ;var D=0,j=!1,O=0;function T(e){
14
+ console.error(JSON.stringify(g,null,2))
15
15
  ;var t=Date.now()
16
- ;throw Date.now()-t>50&&j<5&&(m=!0,P(0),j++),e}
17
- var O=Date.now();function P(t){
16
+ ;throw Date.now()-t>50&&O<5&&(console.log("DEBUG ITERATION: "+O),
17
+ j=!0,P(0),O++),e}var I=Date.now();function P(t){
18
18
  var n=(c||u)&&Date.now()
19
- ;n&&n-O>=c&&(console.log(g),O=n),g+="number"==typeof t?t:1
20
- ;for(var r=u&&n,o=function(){try{var t=e(y)
19
+ ;n&&n-I>=c&&(console.log(D),I=n),D+="number"==typeof t?t:1
20
+ ;for(var o=u&&n,r=function(){try{var t=e(g)
21
21
  ;if("object"==typeof t&&t&&"function"==typeof t.then)return{
22
- value:t.then(P).catch(D)}
23
- ;if(r&&Date.now()-r>=u)return{
22
+ value:t.catch(T).then(P)}
23
+ ;if(o&&Date.now()-o>=u)return{
24
24
  value:(i?new Promise((function(e){
25
25
  setTimeout((function(){e(t)}),i)
26
26
  })):Promise.resolve(t)).then(P)}
27
- ;g+="number"==typeof t?t:1}catch(e){D(e)}
28
- };m||d();){var a=o()
29
- ;if("object"==typeof a)return a.value}return g}
27
+ ;D+="number"==typeof t?t:1}catch(e){T(e)}
28
+ };j||w();){var a=r()
29
+ ;if("object"==typeof a)return a.value}
30
+ return l&&console.log("variants: "+D),D}
30
31
  return P(0)}}
31
32
  },Object.defineProperty(e,"__esModule",{value:!0})
32
33
  }({});
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createTestVariants = require('./createTestVariants.cjs');
5
+ var testVariants_createTestVariants = require('./test-variants/createTestVariants.cjs');
6
6
 
7
7
 
8
8
 
9
- exports.createTestVariants = createTestVariants.createTestVariants;
9
+ exports.createTestVariants = testVariants_createTestVariants.createTestVariants;
@@ -1 +1 @@
1
- export { c as createTestVariants } from './createTestVariants.mjs';
1
+ export { createTestVariants } from './test-variants/createTestVariants.mjs';
@@ -2,8 +2,115 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createTestVariants = require('../createTestVariants.cjs');
5
+ /* eslint-disable @typescript-eslint/no-shadow */
6
+ function createTestVariants(test) {
7
+ return function testVariantsArgs(args) {
8
+ return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
9
+ const argsKeys = Object.keys(args);
10
+ const argsValues = Object.values(args);
11
+ const argsLength = argsKeys.length;
12
+ const variantArgs = {};
13
+ function getArgValues(nArg) {
14
+ let argValues = argsValues[nArg];
15
+ if (typeof argValues === 'function') {
16
+ argValues = argValues(variantArgs);
17
+ }
18
+ return argValues;
19
+ }
20
+ const indexes = [];
21
+ const values = [];
22
+ for (let nArg = 0; nArg < argsLength; nArg++) {
23
+ indexes[nArg] = -1;
24
+ values[nArg] = [];
25
+ }
26
+ values[0] = getArgValues(0);
27
+ function nextVariant() {
28
+ for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
29
+ const index = indexes[nArg] + 1;
30
+ if (index < values[nArg].length) {
31
+ indexes[nArg] = index;
32
+ variantArgs[argsKeys[nArg]] = values[nArg][index];
33
+ for (nArg++; nArg < argsLength; nArg++) {
34
+ const argValues = getArgValues(nArg);
35
+ if (argValues.length === 0) {
36
+ break;
37
+ }
38
+ indexes[nArg] = 0;
39
+ values[nArg] = argValues;
40
+ variantArgs[argsKeys[nArg]] = argValues[0];
41
+ }
42
+ if (nArg >= argsLength) {
43
+ return true;
44
+ }
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ let iterations = 0;
50
+ let debug = false;
51
+ let debugIteration = 0;
52
+ function onError(err) {
53
+ console.error(JSON.stringify(variantArgs, null, 2));
54
+ // console.error(err)
55
+ // rerun failed variant 5 times for debug
56
+ const time0 = Date.now();
57
+ // eslint-disable-next-line no-debugger
58
+ debugger;
59
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
60
+ console.log('DEBUG ITERATION: ' + debugIteration);
61
+ debug = true;
62
+ next(0);
63
+ debugIteration++;
64
+ }
65
+ throw err;
66
+ }
67
+ function onCompleted() {
68
+ if (logCompleted) {
69
+ console.log('variants: ' + iterations);
70
+ }
71
+ }
72
+ let prevLogTime = Date.now();
73
+ function next(value) {
74
+ const now = (logInterval || pauseInterval) && Date.now();
75
+ if (now) {
76
+ if (now - prevLogTime >= logInterval) {
77
+ // the log is required to prevent the karma browserNoActivityTimeout
78
+ console.log(iterations);
79
+ prevLogTime = now;
80
+ }
81
+ }
82
+ iterations += typeof value === 'number' ? value : 1;
83
+ const syncCallStartTime = pauseInterval && now;
84
+ while (debug || nextVariant()) {
85
+ try {
86
+ const promiseOrIterations = test(variantArgs);
87
+ if (typeof promiseOrIterations === 'object'
88
+ && promiseOrIterations
89
+ && typeof promiseOrIterations.then === 'function') {
90
+ return promiseOrIterations.catch(onError).then(next);
91
+ }
92
+ if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
93
+ const pausePromise = pauseTime
94
+ ? new Promise(resolve => {
95
+ setTimeout(() => {
96
+ resolve(promiseOrIterations);
97
+ }, pauseTime);
98
+ })
99
+ : Promise.resolve(promiseOrIterations);
100
+ return pausePromise.then(next);
101
+ }
102
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
103
+ }
104
+ catch (err) {
105
+ onError(err);
106
+ }
107
+ }
108
+ onCompleted();
109
+ return iterations;
110
+ }
111
+ return next(0);
112
+ };
113
+ };
114
+ }
6
115
 
7
-
8
-
9
- exports.createTestVariants = createTestVariants.createTestVariants;
116
+ exports.createTestVariants = createTestVariants;
@@ -12,6 +12,8 @@ export declare type TestVariantsCallParams = {
12
12
  pauseTime?: number;
13
13
  /** console log current iterations, required to prevent the karma browserNoActivityTimeout */
14
14
  logInterval?: number;
15
+ /** console log iterations on test completed */
16
+ logCompleted?: boolean;
15
17
  };
16
18
  export declare function createTestVariants<TArgs extends object>(test: (args: TArgs) => Promise<number | void> | number | void): TestVariantsSetArgs<TArgs>;
17
19
  export {};
@@ -1 +1,112 @@
1
- export { c as createTestVariants } from '../createTestVariants.mjs';
1
+ /* eslint-disable @typescript-eslint/no-shadow */
2
+ function createTestVariants(test) {
3
+ return function testVariantsArgs(args) {
4
+ return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
5
+ const argsKeys = Object.keys(args);
6
+ const argsValues = Object.values(args);
7
+ const argsLength = argsKeys.length;
8
+ const variantArgs = {};
9
+ function getArgValues(nArg) {
10
+ let argValues = argsValues[nArg];
11
+ if (typeof argValues === 'function') {
12
+ argValues = argValues(variantArgs);
13
+ }
14
+ return argValues;
15
+ }
16
+ const indexes = [];
17
+ const values = [];
18
+ for (let nArg = 0; nArg < argsLength; nArg++) {
19
+ indexes[nArg] = -1;
20
+ values[nArg] = [];
21
+ }
22
+ values[0] = getArgValues(0);
23
+ function nextVariant() {
24
+ for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
25
+ const index = indexes[nArg] + 1;
26
+ if (index < values[nArg].length) {
27
+ indexes[nArg] = index;
28
+ variantArgs[argsKeys[nArg]] = values[nArg][index];
29
+ for (nArg++; nArg < argsLength; nArg++) {
30
+ const argValues = getArgValues(nArg);
31
+ if (argValues.length === 0) {
32
+ break;
33
+ }
34
+ indexes[nArg] = 0;
35
+ values[nArg] = argValues;
36
+ variantArgs[argsKeys[nArg]] = argValues[0];
37
+ }
38
+ if (nArg >= argsLength) {
39
+ return true;
40
+ }
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ let iterations = 0;
46
+ let debug = false;
47
+ let debugIteration = 0;
48
+ function onError(err) {
49
+ console.error(JSON.stringify(variantArgs, null, 2));
50
+ // console.error(err)
51
+ // rerun failed variant 5 times for debug
52
+ const time0 = Date.now();
53
+ // eslint-disable-next-line no-debugger
54
+ debugger;
55
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
56
+ console.log('DEBUG ITERATION: ' + debugIteration);
57
+ debug = true;
58
+ next(0);
59
+ debugIteration++;
60
+ }
61
+ throw err;
62
+ }
63
+ function onCompleted() {
64
+ if (logCompleted) {
65
+ console.log('variants: ' + iterations);
66
+ }
67
+ }
68
+ let prevLogTime = Date.now();
69
+ function next(value) {
70
+ const now = (logInterval || pauseInterval) && Date.now();
71
+ if (now) {
72
+ if (now - prevLogTime >= logInterval) {
73
+ // the log is required to prevent the karma browserNoActivityTimeout
74
+ console.log(iterations);
75
+ prevLogTime = now;
76
+ }
77
+ }
78
+ iterations += typeof value === 'number' ? value : 1;
79
+ const syncCallStartTime = pauseInterval && now;
80
+ while (debug || nextVariant()) {
81
+ try {
82
+ const promiseOrIterations = test(variantArgs);
83
+ if (typeof promiseOrIterations === 'object'
84
+ && promiseOrIterations
85
+ && typeof promiseOrIterations.then === 'function') {
86
+ return promiseOrIterations.catch(onError).then(next);
87
+ }
88
+ if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
89
+ const pausePromise = pauseTime
90
+ ? new Promise(resolve => {
91
+ setTimeout(() => {
92
+ resolve(promiseOrIterations);
93
+ }, pauseTime);
94
+ })
95
+ : Promise.resolve(promiseOrIterations);
96
+ return pausePromise.then(next);
97
+ }
98
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
99
+ }
100
+ catch (err) {
101
+ onError(err);
102
+ }
103
+ }
104
+ onCompleted();
105
+ return iterations;
106
+ }
107
+ return next(0);
108
+ };
109
+ };
110
+ }
111
+
112
+ export { createTestVariants };
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var rdtsc = require('rdtsc');
4
- var createTestVariants = require('../createTestVariants.cjs');
4
+ var testVariants_createTestVariants = require('./createTestVariants.cjs');
5
5
 
6
6
  describe('test > testVariants perf', function () {
7
7
  this.timeout(300000);
8
8
  it('sync', function () {
9
9
  let value = 0;
10
- const testVariantsSync = createTestVariants.createTestVariants(({ a, b, c }) => {
10
+ const testVariantsSync = testVariants_createTestVariants.createTestVariants(({ a, b, c }) => {
11
11
  if (a === 1 && b === '4' && c === false) {
12
12
  value++;
13
13
  }
@@ -1,5 +1,5 @@
1
1
  import { calcPerformance } from 'rdtsc';
2
- import { c as createTestVariants } from '../createTestVariants.mjs';
2
+ import { createTestVariants } from './createTestVariants.mjs';
3
3
 
4
4
  describe('test > testVariants perf', function () {
5
5
  this.timeout(300000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "description": "Runs a test function with all possible combinations of its parameters.",
5
5
  "main": "dist/lib/index.cjs",
6
6
  "module": "dist/lib/index.mjs",
@@ -44,7 +44,7 @@
44
44
  "@flemist/test-utils": "0.0.5",
45
45
  "@rollup/plugin-alias": "3.1.9",
46
46
  "@rollup/plugin-babel": "5.3.1",
47
- "@rollup/plugin-commonjs": "22.0.0",
47
+ "@rollup/plugin-commonjs": "=21.1.0",
48
48
  "@rollup/plugin-inject": "4.0.4",
49
49
  "@rollup/plugin-json": "4.1.0",
50
50
  "@rollup/plugin-multi-entry": "4.1.0",
@@ -57,7 +57,7 @@
57
57
  "@types/node": "18.0.0",
58
58
  "cpy-cli": "3.1.1",
59
59
  "eslint": "8.18.0",
60
- "eslint-config-pro": "3.0.13",
60
+ "eslint-config-pro": "3.0.14",
61
61
  "fs-extra": "10.1.0",
62
62
  "globby": "=11.1.0",
63
63
  "karma": "6.4.0",
@@ -71,7 +71,7 @@
71
71
  "nyc": "15.1.0",
72
72
  "rdtsc": "2.0.0",
73
73
  "rimraf": "3.0.2",
74
- "rollup": "2.75.6",
74
+ "rollup": "2.75.7",
75
75
  "rollup-plugin-delete": "2.0.0",
76
76
  "rollup-plugin-istanbul": "3.0.0",
77
77
  "rollup-plugin-multi-input": "1.3.1",
@@ -1,107 +0,0 @@
1
- 'use strict';
2
-
3
- /* eslint-disable @typescript-eslint/no-shadow */
4
- function createTestVariants(test) {
5
- return function testVariantsArgs(args) {
6
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, } = {}) {
7
- const argsKeys = Object.keys(args);
8
- const argsValues = Object.values(args);
9
- const argsLength = argsKeys.length;
10
- const variantArgs = {};
11
- function getArgValues(nArg) {
12
- let argValues = argsValues[nArg];
13
- if (typeof argValues === 'function') {
14
- argValues = argValues(variantArgs);
15
- }
16
- return argValues;
17
- }
18
- const indexes = [];
19
- const values = [];
20
- for (let nArg = 0; nArg < argsLength; nArg++) {
21
- indexes[nArg] = -1;
22
- values[nArg] = [];
23
- }
24
- values[0] = getArgValues(0);
25
- function nextVariant() {
26
- for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
27
- const index = indexes[nArg] + 1;
28
- if (index < values[nArg].length) {
29
- indexes[nArg] = index;
30
- variantArgs[argsKeys[nArg]] = values[nArg][index];
31
- for (nArg++; nArg < argsLength; nArg++) {
32
- const argValues = getArgValues(nArg);
33
- if (argValues.length === 0) {
34
- break;
35
- }
36
- indexes[nArg] = 0;
37
- values[nArg] = argValues;
38
- variantArgs[argsKeys[nArg]] = argValues[0];
39
- }
40
- if (nArg >= argsLength) {
41
- return true;
42
- }
43
- }
44
- }
45
- return false;
46
- }
47
- let iterations = 0;
48
- let debug = false;
49
- let debugIteration = 0;
50
- function onError(err) {
51
- console.error(JSON.stringify(variantArgs, null, 2));
52
- console.error(err);
53
- // rerun failed variant 5 times for debug
54
- const time0 = Date.now();
55
- // eslint-disable-next-line no-debugger
56
- debugger;
57
- if (Date.now() - time0 > 50 && debugIteration < 5) {
58
- debug = true;
59
- next(0);
60
- debugIteration++;
61
- }
62
- throw err;
63
- }
64
- let prevLogTime = Date.now();
65
- function next(value) {
66
- const now = (logInterval || pauseInterval) && Date.now();
67
- if (now) {
68
- if (now - prevLogTime >= logInterval) {
69
- // the log is required to prevent the karma browserNoActivityTimeout
70
- console.log(iterations);
71
- prevLogTime = now;
72
- }
73
- }
74
- iterations += typeof value === 'number' ? value : 1;
75
- const syncCallStartTime = pauseInterval && now;
76
- while (debug || nextVariant()) {
77
- try {
78
- const promiseOrIterations = test(variantArgs);
79
- if (typeof promiseOrIterations === 'object'
80
- && promiseOrIterations
81
- && typeof promiseOrIterations.then === 'function') {
82
- return promiseOrIterations.then(next).catch(onError);
83
- }
84
- if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
85
- const pausePromise = pauseTime
86
- ? new Promise(resolve => {
87
- setTimeout(() => {
88
- resolve(promiseOrIterations);
89
- }, pauseTime);
90
- })
91
- : Promise.resolve(promiseOrIterations);
92
- return pausePromise.then(next);
93
- }
94
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
95
- }
96
- catch (err) {
97
- onError(err);
98
- }
99
- }
100
- return iterations;
101
- }
102
- return next(0);
103
- };
104
- };
105
- }
106
-
107
- exports.createTestVariants = createTestVariants;
@@ -1,105 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-shadow */
2
- function createTestVariants(test) {
3
- return function testVariantsArgs(args) {
4
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, } = {}) {
5
- const argsKeys = Object.keys(args);
6
- const argsValues = Object.values(args);
7
- const argsLength = argsKeys.length;
8
- const variantArgs = {};
9
- function getArgValues(nArg) {
10
- let argValues = argsValues[nArg];
11
- if (typeof argValues === 'function') {
12
- argValues = argValues(variantArgs);
13
- }
14
- return argValues;
15
- }
16
- const indexes = [];
17
- const values = [];
18
- for (let nArg = 0; nArg < argsLength; nArg++) {
19
- indexes[nArg] = -1;
20
- values[nArg] = [];
21
- }
22
- values[0] = getArgValues(0);
23
- function nextVariant() {
24
- for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
25
- const index = indexes[nArg] + 1;
26
- if (index < values[nArg].length) {
27
- indexes[nArg] = index;
28
- variantArgs[argsKeys[nArg]] = values[nArg][index];
29
- for (nArg++; nArg < argsLength; nArg++) {
30
- const argValues = getArgValues(nArg);
31
- if (argValues.length === 0) {
32
- break;
33
- }
34
- indexes[nArg] = 0;
35
- values[nArg] = argValues;
36
- variantArgs[argsKeys[nArg]] = argValues[0];
37
- }
38
- if (nArg >= argsLength) {
39
- return true;
40
- }
41
- }
42
- }
43
- return false;
44
- }
45
- let iterations = 0;
46
- let debug = false;
47
- let debugIteration = 0;
48
- function onError(err) {
49
- console.error(JSON.stringify(variantArgs, null, 2));
50
- console.error(err);
51
- // rerun failed variant 5 times for debug
52
- const time0 = Date.now();
53
- // eslint-disable-next-line no-debugger
54
- debugger;
55
- if (Date.now() - time0 > 50 && debugIteration < 5) {
56
- debug = true;
57
- next(0);
58
- debugIteration++;
59
- }
60
- throw err;
61
- }
62
- let prevLogTime = Date.now();
63
- function next(value) {
64
- const now = (logInterval || pauseInterval) && Date.now();
65
- if (now) {
66
- if (now - prevLogTime >= logInterval) {
67
- // the log is required to prevent the karma browserNoActivityTimeout
68
- console.log(iterations);
69
- prevLogTime = now;
70
- }
71
- }
72
- iterations += typeof value === 'number' ? value : 1;
73
- const syncCallStartTime = pauseInterval && now;
74
- while (debug || nextVariant()) {
75
- try {
76
- const promiseOrIterations = test(variantArgs);
77
- if (typeof promiseOrIterations === 'object'
78
- && promiseOrIterations
79
- && typeof promiseOrIterations.then === 'function') {
80
- return promiseOrIterations.then(next).catch(onError);
81
- }
82
- if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
83
- const pausePromise = pauseTime
84
- ? new Promise(resolve => {
85
- setTimeout(() => {
86
- resolve(promiseOrIterations);
87
- }, pauseTime);
88
- })
89
- : Promise.resolve(promiseOrIterations);
90
- return pausePromise.then(next);
91
- }
92
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
93
- }
94
- catch (err) {
95
- onError(err);
96
- }
97
- }
98
- return iterations;
99
- }
100
- return next(0);
101
- };
102
- };
103
- }
104
-
105
- export { createTestVariants as c };
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- function delay(milliseconds, abortSignal) {
4
- return new Promise(resolve => {
5
- if (abortSignal && abortSignal.aborted) {
6
- resolve();
7
- return;
8
- }
9
- const timer = setTimeout(resolve, milliseconds);
10
- if (abortSignal) {
11
- abortSignal.addEventListener('abort', () => {
12
- clearTimeout(timer);
13
- resolve();
14
- });
15
- }
16
- });
17
- }
18
-
19
- exports.delay = delay;
@@ -1,17 +0,0 @@
1
- function delay(milliseconds, abortSignal) {
2
- return new Promise(resolve => {
3
- if (abortSignal && abortSignal.aborted) {
4
- resolve();
5
- return;
6
- }
7
- const timer = setTimeout(resolve, milliseconds);
8
- if (abortSignal) {
9
- abortSignal.addEventListener('abort', () => {
10
- clearTimeout(timer);
11
- resolve();
12
- });
13
- }
14
- });
15
- }
16
-
17
- export { delay as d };