Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit19fdb59

Browse files
committed
Require Node.js 20
1 parent8f9d742 commit19fdb59

File tree

7 files changed

+51
-65
lines changed

7 files changed

+51
-65
lines changed

‎.github/funding.yml‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎.github/workflows/main.yml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ jobs:
1010
fail-fast:false
1111
matrix:
1212
node-version:
13+
-24
1314
-20
14-
-18
15-
-16
1615
steps:
17-
-uses:actions/checkout@v3
18-
-uses:actions/setup-node@v3
16+
-uses:actions/checkout@v5
17+
-uses:actions/setup-node@v6
1918
with:
2019
node-version:${{ matrix.node-version }}
2120
-run:npm install

‎index.js‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import{setTimeoutassafeSetTimeout,clearTimeoutassafeClearTimeout}from'unlimited-timeout';
22
importrandomIntegerfrom'random-int';
33

4-
constcreateAbortError=()=>{
5-
consterror=newError('Delay aborted');
6-
error.name='AbortError';
7-
returnerror;
8-
};
9-
104
constclearMethods=newWeakMap();
115

126
exportfunctioncreateDelay({clearTimeout:defaultClear,setTimeout:defaultSet}={}){
137
// We cannot use `async` here as we need the promise identity.
148
return(milliseconds,{value, signal}={})=>{
15-
// TODO: Use `signal?.throwIfAborted()` when targeting Node.js 18.
169
if(signal?.aborted){
17-
returnPromise.reject(createAbortError());
10+
returnPromise.reject(signal.reason);
1811
}
1912

2013
lettimeoutId;
@@ -24,7 +17,7 @@ export function createDelay({clearTimeout: defaultClear, setTimeout: defaultSet}
2417

2518
constsignalListener=()=>{
2619
clear(timeoutId);
27-
rejectFunction(createAbortError());
20+
rejectFunction(signal.reason);
2821
};
2922

3023
constcleanup=()=>{
@@ -61,7 +54,7 @@ const delay = createDelay({setTimeout: safeSetTimeout, clearTimeout: safeClearTi
6154

6255
exportdefaultdelay;
6356

64-
exportasyncfunctionrangeDelay(minimum,maximum,options={}){
57+
exportasyncfunctionrangeDelay(minimum,maximum,options){
6558
returndelay(randomInteger(minimum,maximum),options);
6659
}
6760

‎index.test-d.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ expectType<Promise<void>>(delay(200));
55

66
expectType<Promise<string>>(delay(200,{value:'🦄'}));
77
expectType<Promise<number>>(delay(200,{value:0}));
8-
expectType<Promise<void>>(
9-
delay(200,{signal:newAbortController().signal}),
10-
);
8+
expectType<Promise<void>>(delay(200,{signal:newAbortController().signal}));
119

1210
expectType<Promise<number>>(rangeDelay(50,200,{value:0}));
1311

@@ -19,7 +17,8 @@ expectType<Promise<number>>(customDelay(200, {value: 0}));
1917

2018
constunrefDelay=createDelay({
2119
clearTimeout,
22-
setTimeout(...arguments_){
23-
returnsetTimeout(...arguments_).unref();
20+
setTimeout(callback,milliseconds){
21+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
22+
return(setTimeout(callback,milliseconds)asany).unref();
2423
},
2524
});

‎package.json‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
"types":"./index.d.ts",
1616
"default":"./index.js"
1717
},
18+
"sideEffects":false,
1819
"engines": {
19-
"node":">=16"
20+
"node":">=20"
2021
},
2122
"scripts": {
22-
"test":"xo &&ava && tsd"
23+
"test":"xo &&node --test && tsd"
2324
},
2425
"files": [
2526
"index.js",
@@ -52,13 +53,9 @@
5253
"unlimited-timeout":"^0.1.0"
5354
},
5455
"devDependencies": {
55-
"ava":"5.2.0",
5656
"in-range":"^3.0.0",
5757
"time-span":"^5.1.0",
58-
"tsd":"^0.28.1",
59-
"xo":"^0.54.2"
60-
},
61-
"ava": {
62-
"serial":true
58+
"tsd":"^0.33.0",
59+
"xo":"^1.2.3"
6360
}
6461
}

‎readme.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
>Delay a promise a specified amount of time
44
5-
*If you target Node.js only, you can use`import {setTimeout} from 'node:timers/promises'; await setTimeout(1000);` instead. This package can still be useful if you need browser support or the extra features.*
5+
>[!TIP]
6+
>If you target Node.js only, you can use`import {setTimeout} from 'node:timers/promises'; await setTimeout(1000);` instead. This package can still be useful if you need browser support or the extra features.
67
78
##Install
89

@@ -67,7 +68,7 @@ console.log(result);
6768

6869
#####signal
6970

70-
Type:[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
71+
Type:[`AbortSignal`](https://developer.mozilla.org/docs/Web/API/AbortSignal)
7172

7273
The returned promise will be rejected with an`AbortError` if the signal is aborted.
7374

‎test.js‎

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,92 @@
1-
importtestfrom'ava';
1+
importtestfrom'node:test';
2+
importassertfrom'node:assert/strict';
23
importtimeSpanfrom'time-span';
34
importinRangefrom'in-range';
45
importdelay,{clearDelay,rangeDelay,createDelay}from'./index.js';
56

6-
test('returns a resolved promise',asynct=>{
7+
test('returns a resolved promise',async()=>{
78
constend=timeSpan();
89
awaitdelay(50);
9-
t.true(inRange(end(),{start:30,end:70}),'is delayed');
10+
assert.ok(inRange(end(),{start:30,end:70}),'is delayed');
1011
});
1112

12-
test('able to resolve a falsy value',asynct=>{
13-
t.is(
13+
test('able to resolve a falsy value',async()=>{
14+
assert.strictEqual(
1415
awaitdelay(50,{value:0}),
1516
0,
1617
);
1718
});
1819

19-
test('delay defaults to 0 ms',asynct=>{
20+
test('delay defaults to 0 ms',async()=>{
2021
constend=timeSpan();
2122
awaitdelay();
22-
t.true(end()<30);
23+
assert.ok(end()<30);
2324
});
2425

25-
test('can clear a delayed resolution',asynct=>{
26+
test('can clear a delayed resolution',async()=>{
2627
constend=timeSpan();
2728
constdelayPromise=delay(1000,{value:'success!'});
2829

2930
clearDelay(delayPromise);
3031
constsuccess=awaitdelayPromise;
3132

32-
t.true(end()<30);
33-
t.is(success,'success!');
33+
assert.ok(end()<30);
34+
assert.strictEqual(success,'success!');
3435
});
3536

36-
test('resolution can be aborted with an AbortSignal',asynct=>{
37+
test('resolution can be aborted with an AbortSignal',async()=>{
3738
constend=timeSpan();
3839
constabortController=newAbortController();
3940

4041
setTimeout(()=>{
4142
abortController.abort();
4243
},1);
4344

44-
awaitt.throwsAsync(
45+
awaitassert.rejects(
4546
delay(1000,{signal:abortController.signal}),
4647
{name:'AbortError'},
4748
);
4849

49-
t.true(end()<30);
50+
assert.ok(end()<30);
5051
});
5152

52-
test('resolution can be aborted with an AbortSignal if a value is passed',asynct=>{
53+
test('resolution can be aborted with an AbortSignal if a value is passed',async()=>{
5354
constend=timeSpan();
5455
constabortController=newAbortController();
5556

5657
setTimeout(()=>{
5758
abortController.abort();
5859
},1);
5960

60-
awaitt.throwsAsync(
61+
awaitassert.rejects(
6162
delay(1000,{value:123,signal:abortController.signal}),
6263
{name:'AbortError'},
6364
);
6465

65-
t.true(end()<30);
66+
assert.ok(end()<30);
6667
});
6768

68-
test('rejects with AbortError if AbortSignal is already aborted',asynct=>{
69+
test('rejects with AbortError if AbortSignal is already aborted',async()=>{
6970
constend=timeSpan();
7071

7172
constabortController=newAbortController();
7273
abortController.abort();
7374

74-
awaitt.throwsAsync(
75+
awaitassert.rejects(
7576
delay(1000,{signal:abortController.signal}),
7677
{name:'AbortError'},
7778
);
7879

79-
t.true(end()<30);
80+
assert.ok(end()<30);
8081
});
8182

82-
test('returns a promise that is resolved in a random range of time',asynct=>{
83+
test('returns a promise that is resolved in a random range of time',async()=>{
8384
constend=timeSpan();
8485
awaitrangeDelay(50,150);
85-
t.true(inRange(end(),{start:30,end:170}),'is delayed');
86+
assert.ok(inRange(end(),{start:30,end:170}),'is delayed');
8687
});
8788

88-
test('can create a new instance with fixed timeout methods',asynct=>{
89+
test('can create a new instance with fixed timeout methods',async()=>{
8990
constcleared=[];
9091
constcallbacks=[];
9192

@@ -102,21 +103,21 @@ test('can create a new instance with fixed timeout methods', async t => {
102103
});
103104

104105
constfirst=custom(50,{value:'first'});
105-
t.is(callbacks.length,1);
106-
t.is(callbacks[0].ms,50);
106+
assert.strictEqual(callbacks.length,1);
107+
assert.strictEqual(callbacks[0].ms,50);
107108
callbacks[0].callback();
108-
t.is(awaitfirst,'first');
109+
assert.strictEqual(awaitfirst,'first');
109110

110111
constsecond=custom(40,{value:'second'});
111-
t.is(callbacks.length,2);
112-
t.is(callbacks[1].ms,40);
112+
assert.strictEqual(callbacks.length,2);
113+
assert.strictEqual(callbacks[1].ms,40);
113114
callbacks[1].callback();
114-
t.is(awaitsecond,'second');
115+
assert.strictEqual(awaitsecond,'second');
115116

116117
constthird=custom(60);
117-
t.is(callbacks.length,3);
118-
t.is(callbacks[2].ms,60);
118+
assert.strictEqual(callbacks.length,3);
119+
assert.strictEqual(callbacks[2].ms,60);
119120
clearDelay(third);
120-
t.is(cleared.length,1);
121-
t.is(cleared[0],callbacks[2].handle);
121+
assert.strictEqual(cleared.length,1);
122+
assert.strictEqual(cleared[0],callbacks[2].handle);
122123
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp