@libp2p/utils
Advanced tools
Comparing version 6.4.0-80ddad5bb to 6.4.0-c1d0b7fa4
import type { AbortOptions } from '@libp2p/interface'; | ||
export interface RepeatingTask { | ||
/** | ||
* Update the interval after which the next iteration of the task will run. | ||
* | ||
* This is useful if, for example, you want to retry a task with a short rest | ||
* duration until it succeeds, then periodically after that. | ||
* | ||
* This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setInterval(ms: number): void; | ||
/** | ||
* Update the amount of time a task will run before the passed abort signal | ||
* will fire. | ||
* | ||
* * This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setTimeout(ms: number): void; | ||
/** | ||
* Start the task running | ||
*/ | ||
start(): void; | ||
/** | ||
* Stop the task running | ||
*/ | ||
stop(): void; | ||
@@ -14,2 +38,4 @@ } | ||
* Whether to schedule the task to run immediately | ||
* | ||
* @default false | ||
*/ | ||
@@ -16,0 +42,0 @@ runImmediately?: boolean; |
@@ -30,2 +30,16 @@ import { setMaxListeners } from '@libp2p/interface'; | ||
return { | ||
setInterval: (ms) => { | ||
interval = ms; | ||
// maybe reschedule | ||
if (timeout != null) { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(runTask, interval); | ||
} | ||
}, | ||
setTimeout: (ms) => { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
options.timeout = ms; | ||
}, | ||
start: () => { | ||
@@ -32,0 +46,0 @@ if (started) { |
{ | ||
"name": "@libp2p/utils", | ||
"version": "6.4.0-80ddad5bb", | ||
"version": "6.4.0-c1d0b7fa4", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -184,5 +184,5 @@ "license": "Apache-2.0 OR MIT", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "5.0.10-80ddad5bb", | ||
"@libp2p/interface": "2.4.1-80ddad5bb", | ||
"@libp2p/logger": "5.1.7-80ddad5bb", | ||
"@libp2p/crypto": "5.0.10-c1d0b7fa4", | ||
"@libp2p/interface": "2.4.1-c1d0b7fa4", | ||
"@libp2p/logger": "5.1.7-c1d0b7fa4", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
@@ -208,3 +208,3 @@ "@sindresorhus/fnv1a": "^3.1.0", | ||
"devDependencies": { | ||
"@libp2p/peer-id": "5.0.11-80ddad5bb", | ||
"@libp2p/peer-id": "5.0.11-c1d0b7fa4", | ||
"@types/netmask": "^2.0.5", | ||
@@ -211,0 +211,0 @@ "aegir": "^45.0.5", |
@@ -6,3 +6,30 @@ import { setMaxListeners } from '@libp2p/interface' | ||
export interface RepeatingTask { | ||
/** | ||
* Update the interval after which the next iteration of the task will run. | ||
* | ||
* This is useful if, for example, you want to retry a task with a short rest | ||
* duration until it succeeds, then periodically after that. | ||
* | ||
* This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setInterval(ms: number): void | ||
/** | ||
* Update the amount of time a task will run before the passed abort signal | ||
* will fire. | ||
* | ||
* * This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setTimeout(ms: number): void | ||
/** | ||
* Start the task running | ||
*/ | ||
start(): void | ||
/** | ||
* Stop the task running | ||
*/ | ||
stop(): void | ||
@@ -20,2 +47,4 @@ } | ||
* Whether to schedule the task to run immediately | ||
* | ||
* @default false | ||
*/ | ||
@@ -59,2 +88,18 @@ runImmediately?: boolean | ||
return { | ||
setInterval: (ms) => { | ||
interval = ms | ||
// maybe reschedule | ||
if (timeout != null) { | ||
clearTimeout(timeout) | ||
timeout = setTimeout(runTask, interval) | ||
} | ||
}, | ||
setTimeout: (ms) => { | ||
if (options == null) { | ||
options = {} | ||
} | ||
options.timeout = ms | ||
}, | ||
start: () => { | ||
@@ -61,0 +106,0 @@ if (started) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
281334
5363
+ Added@libp2p/crypto@5.0.10-c1d0b7fa4(transitive)
+ Added@libp2p/interface@2.4.1-c1d0b7fa4(transitive)
+ Added@libp2p/logger@5.1.7-c1d0b7fa4(transitive)
- Removed@libp2p/crypto@5.0.10-80ddad5bb(transitive)
- Removed@libp2p/interface@2.4.1-80ddad5bb(transitive)
- Removed@libp2p/logger@5.1.7-80ddad5bb(transitive)