@libp2p/utils 6.3.1-fe8af37a1 → 6.4.0-26313e695
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/dist/src/is-async-generator.d.ts +2 -0
- package/dist/src/is-async-generator.d.ts.map +1 -0
- package/dist/src/is-async-generator.js +12 -0
- package/dist/src/is-async-generator.js.map +1 -0
- package/dist/src/is-generator.d.ts +2 -0
- package/dist/src/is-generator.d.ts.map +1 -0
- package/dist/src/is-generator.js +12 -0
- package/dist/src/is-generator.js.map +1 -0
- package/dist/src/repeating-task.d.ts +26 -0
- package/dist/src/repeating-task.d.ts.map +1 -1
- package/dist/src/repeating-task.js +14 -0
- package/dist/src/repeating-task.js.map +1 -1
- package/package.json +13 -5
- package/src/is-async-generator.ts +16 -0
- package/src/is-generator.ts +15 -0
- package/src/repeating-task.ts +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-async-generator.d.ts","sourceRoot":"","sources":["../../src/is-async-generator.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAerE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isAsyncGenerator(obj) {
|
|
2
|
+
if (obj == null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const asyncIterator = obj?.[Symbol.asyncIterator];
|
|
6
|
+
if (typeof asyncIterator !== 'function') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const instance = obj;
|
|
10
|
+
return typeof instance.next === 'function';
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=is-async-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-async-generator.js","sourceRoot":"","sources":["../../src/is-async-generator.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAE,GAAY;IAC5C,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,aAAa,GAAI,GAA4C,EAAE,CACnE,MAAM,CAAC,aAAa,CACrB,CAAA;IAED,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;QACxC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,GAAyB,CAAA;IAC1C,OAAO,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-generator.d.ts","sourceRoot":"","sources":["../../src/is-generator.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAc3D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isGenerator(obj) {
|
|
2
|
+
if (obj == null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const iterator = obj?.[Symbol.iterator];
|
|
6
|
+
if (typeof iterator !== 'function') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const instance = obj;
|
|
10
|
+
return typeof instance.next === 'function';
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=is-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-generator.js","sourceRoot":"","sources":["../../src/is-generator.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAE,GAAY;IACvC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,QAAQ,GAAI,GAAuC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAE5E,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,GAAyB,CAAA;IAE1C,OAAO,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAA;AAC5C,CAAC"}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import type { AbortOptions } from '@libp2p/interface';
|
|
2
2
|
export interface RepeatingTask {
|
|
3
|
+
/**
|
|
4
|
+
* Update the interval after which the next iteration of the task will run.
|
|
5
|
+
*
|
|
6
|
+
* This is useful if, for example, you want to retry a task with a short rest
|
|
7
|
+
* duration until it succeeds, then periodically after that.
|
|
8
|
+
*
|
|
9
|
+
* This only affects the next iteration of the task, if it is currently
|
|
10
|
+
* running, that run will not be interrupted.
|
|
11
|
+
*/
|
|
12
|
+
setInterval(ms: number): void;
|
|
13
|
+
/**
|
|
14
|
+
* Update the amount of time a task will run before the passed abort signal
|
|
15
|
+
* will fire.
|
|
16
|
+
*
|
|
17
|
+
* * This only affects the next iteration of the task, if it is currently
|
|
18
|
+
* running, that run will not be interrupted.
|
|
19
|
+
*/
|
|
20
|
+
setTimeout(ms: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* Start the task running
|
|
23
|
+
*/
|
|
3
24
|
start(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Stop the task running
|
|
27
|
+
*/
|
|
4
28
|
stop(): void;
|
|
5
29
|
}
|
|
6
30
|
export interface RepeatingTaskOptions {
|
|
@@ -11,6 +35,8 @@ export interface RepeatingTaskOptions {
|
|
|
11
35
|
timeout?: number;
|
|
12
36
|
/**
|
|
13
37
|
* Whether to schedule the task to run immediately
|
|
38
|
+
*
|
|
39
|
+
* @default false
|
|
14
40
|
*/
|
|
15
41
|
runImmediately?: boolean;
|
|
16
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeating-task.d.ts","sourceRoot":"","sources":["../../src/repeating-task.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,aAAa;IAC5B,KAAK,IAAI,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"repeating-task.d.ts","sourceRoot":"","sources":["../../src/repeating-task.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAA;IAEb;;OAEG;IACH,IAAI,IAAI,IAAI,CAAA;CACb;AAED,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,wBAAgB,aAAa,CAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CA2EpJ"}
|
|
@@ -27,6 +27,20 @@ export function repeatingTask(fn, interval, options) {
|
|
|
27
27
|
}
|
|
28
28
|
let started = false;
|
|
29
29
|
return {
|
|
30
|
+
setInterval: (ms) => {
|
|
31
|
+
interval = ms;
|
|
32
|
+
// maybe reschedule
|
|
33
|
+
if (timeout != null) {
|
|
34
|
+
clearTimeout(timeout);
|
|
35
|
+
timeout = setTimeout(runTask, interval);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
setTimeout: (ms) => {
|
|
39
|
+
if (options == null) {
|
|
40
|
+
options = {};
|
|
41
|
+
}
|
|
42
|
+
options.timeout = ms;
|
|
43
|
+
},
|
|
30
44
|
start: () => {
|
|
31
45
|
if (started) {
|
|
32
46
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeating-task.js","sourceRoot":"","sources":["../../src/repeating-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"repeating-task.js","sourceRoot":"","sources":["../../src/repeating-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAkDtC,MAAM,UAAU,aAAa,CAAE,EAAoD,EAAE,QAAgB,EAAE,OAA8B;IACnI,IAAI,OAAsC,CAAA;IAC1C,IAAI,kBAAmC,CAAA;IAEvC,SAAS,OAAO;QACd,MAAM,IAAI,GAAiB;YACzB,MAAM,EAAE,kBAAkB,CAAC,MAAM;SAClC,CAAA;QAED,IAAI,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;YAC3F,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAEjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,CAAC;QAED,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAChC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC,CAAC;aACC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;aACf,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACtC,gCAAgC;gBAChC,OAAM;YACR,CAAC;YAED,aAAa;YACb,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACN,CAAC;IAED,I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.
|
|
3
|
+
"version": "6.4.0-26313e695",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
|
|
@@ -84,6 +84,14 @@
|
|
|
84
84
|
"types": "./dist/src/ip-port-to-multiaddr.d.ts",
|
|
85
85
|
"import": "./dist/src/ip-port-to-multiaddr.js"
|
|
86
86
|
},
|
|
87
|
+
"./is-async-generator": {
|
|
88
|
+
"types": "./dist/src/is-async-generator.d.ts",
|
|
89
|
+
"import": "./dist/src/is-async-generator.js"
|
|
90
|
+
},
|
|
91
|
+
"./is-generator": {
|
|
92
|
+
"types": "./dist/src/is-generator.d.ts",
|
|
93
|
+
"import": "./dist/src/is-generator.js"
|
|
94
|
+
},
|
|
87
95
|
"./is-promise": {
|
|
88
96
|
"types": "./dist/src/is-promise.d.ts",
|
|
89
97
|
"import": "./dist/src/is-promise.js"
|
|
@@ -173,9 +181,9 @@
|
|
|
173
181
|
"dependencies": {
|
|
174
182
|
"@chainsafe/is-ip": "^2.0.2",
|
|
175
183
|
"@chainsafe/netmask": "^2.0.0",
|
|
176
|
-
"@libp2p/crypto": "5.0.
|
|
177
|
-
"@libp2p/interface": "2.4.
|
|
178
|
-
"@libp2p/logger": "5.1.
|
|
184
|
+
"@libp2p/crypto": "5.0.10-26313e695",
|
|
185
|
+
"@libp2p/interface": "2.4.1-26313e695",
|
|
186
|
+
"@libp2p/logger": "5.1.7-26313e695",
|
|
179
187
|
"@multiformats/multiaddr": "^12.3.3",
|
|
180
188
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
181
189
|
"@types/murmurhash3js-revisited": "^3.0.3",
|
|
@@ -196,7 +204,7 @@
|
|
|
196
204
|
"uint8arrays": "^5.1.0"
|
|
197
205
|
},
|
|
198
206
|
"devDependencies": {
|
|
199
|
-
"@libp2p/peer-id": "5.0.
|
|
207
|
+
"@libp2p/peer-id": "5.0.11-26313e695",
|
|
200
208
|
"@types/netmask": "^2.0.5",
|
|
201
209
|
"aegir": "^45.0.5",
|
|
202
210
|
"benchmark": "^2.1.4",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isAsyncGenerator (obj: unknown): obj is AsyncGenerator {
|
|
2
|
+
if (obj == null) {
|
|
3
|
+
return false
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const asyncIterator = (obj as { [Symbol.asyncIterator]?: unknown })?.[
|
|
7
|
+
Symbol.asyncIterator
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
if (typeof asyncIterator !== 'function') {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const instance = obj as { next?: unknown }
|
|
15
|
+
return typeof instance.next === 'function'
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function isGenerator (obj: unknown): obj is Generator {
|
|
2
|
+
if (obj == null) {
|
|
3
|
+
return false
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const iterator = (obj as { [Symbol.iterator]?: unknown })?.[Symbol.iterator]
|
|
7
|
+
|
|
8
|
+
if (typeof iterator !== 'function') {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const instance = obj as { next?: unknown }
|
|
13
|
+
|
|
14
|
+
return typeof instance.next === 'function'
|
|
15
|
+
}
|
package/src/repeating-task.ts
CHANGED
|
@@ -3,7 +3,34 @@ import { anySignal } from 'any-signal'
|
|
|
3
3
|
import type { AbortOptions } from '@libp2p/interface'
|
|
4
4
|
|
|
5
5
|
export interface RepeatingTask {
|
|
6
|
+
/**
|
|
7
|
+
* Update the interval after which the next iteration of the task will run.
|
|
8
|
+
*
|
|
9
|
+
* This is useful if, for example, you want to retry a task with a short rest
|
|
10
|
+
* duration until it succeeds, then periodically after that.
|
|
11
|
+
*
|
|
12
|
+
* This only affects the next iteration of the task, if it is currently
|
|
13
|
+
* running, that run will not be interrupted.
|
|
14
|
+
*/
|
|
15
|
+
setInterval(ms: number): void
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Update the amount of time a task will run before the passed abort signal
|
|
19
|
+
* will fire.
|
|
20
|
+
*
|
|
21
|
+
* * This only affects the next iteration of the task, if it is currently
|
|
22
|
+
* running, that run will not be interrupted.
|
|
23
|
+
*/
|
|
24
|
+
setTimeout(ms: number): void
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Start the task running
|
|
28
|
+
*/
|
|
6
29
|
start(): void
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Stop the task running
|
|
33
|
+
*/
|
|
7
34
|
stop(): void
|
|
8
35
|
}
|
|
9
36
|
|
|
@@ -16,6 +43,8 @@ export interface RepeatingTaskOptions {
|
|
|
16
43
|
|
|
17
44
|
/**
|
|
18
45
|
* Whether to schedule the task to run immediately
|
|
46
|
+
*
|
|
47
|
+
* @default false
|
|
19
48
|
*/
|
|
20
49
|
runImmediately?: boolean
|
|
21
50
|
}
|
|
@@ -54,6 +83,22 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
|
|
|
54
83
|
let started = false
|
|
55
84
|
|
|
56
85
|
return {
|
|
86
|
+
setInterval: (ms) => {
|
|
87
|
+
interval = ms
|
|
88
|
+
|
|
89
|
+
// maybe reschedule
|
|
90
|
+
if (timeout != null) {
|
|
91
|
+
clearTimeout(timeout)
|
|
92
|
+
timeout = setTimeout(runTask, interval)
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
setTimeout: (ms) => {
|
|
96
|
+
if (options == null) {
|
|
97
|
+
options = {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
options.timeout = ms
|
|
101
|
+
},
|
|
57
102
|
start: () => {
|
|
58
103
|
if (started) {
|
|
59
104
|
return
|