![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
node-endeavour
Advanced tools
Flexible, fault-tolerant operations for Typescript.
>=4.6.0
>=2.0
npm install node-endeavour --save
import endeavour from 'node-endeavour'
function unreliable () {
if (Math.random <= 0.25) return Promise.resolve()
return Promise.reject()
}
// create a fault tolerant operation. This will be retried
// 10 times, backing off exponentially with no maximum delay.
const faultTolerant = endeavour(unreliable)
async function main () {
let result
try {
result = await faultTolerant()
} catch (error) {
console.log(error)
}
}
main()
Creates a new EndeavourRunnable
; a wrapped version of your function that will retry indefinitely, or up until some specified limit. The default options are as follows:
retries
The maximum amount of times to retry the operation. Defaults to 10
.constant
The base in exponential backoff, or the slope in linear backoff. Defaults to 2
.minTimeout
The number of milliseconds before starting the first retry. Default is 1000
.maxTimeout
The maximum number of milliseconds between two retries. Default is Infinity
.You may also specify this
(useful for wrapping instance methods).
class Thing {
doSomethingUnreliable () {}
}
const instance = new Thing()
const faultTolerant = endeavour(instance.doSomethingUnreliable, instance)
faultTolerant()
.then(res => { console.log('yay!') })
.catch(e => { console.log(':(')) })
See the decorators section for a more terse way of handling these cases.
Using your wrapped function from endeavour(...)
works much in the same way as before. Arguments are be passed like this:
myFaultTolerantOperation(['some', 'arguments'])
The wrapped operation also accepts and optional function to allow for greater control over how retries should proceed.
faultTolerantOperation((result, next) => {
if (result.error instanceof MyCustomError) {
return next(new Error('something went horribly wrong :('))
}
})
Calling next()
with an error will stop your operation. You can also pass in an new array of arguments for subsequent retries.
faultTolerantOperation((result, next) => {
if (result.error instanceof MyCustomError) {
return next(['new', 'args'])
}
})
You could also just inspect the result of the last attempt.
faultTolerantOperation(result => {
console.log(result.error)
})
A decorator for providing metadata about how retriable methods in a class should operate. Takes the options defined here.
Provides the same functionality as endeavour, but for class methods.
@endeavourable({ retries: 15 })
class {
// retried 15 times
@endeavourify()
unreliableMethod () {
if (Math.random <= 0.25) return Promise.resolve()
return Promise.reject()
}
// retried 5 times
@endeavourify({ retries: 5 })
doSomething () { }
// retried 10 times
@endeavourify()
otherThing() { }
}
When no arguments are given to @endeavourable
or @endeavourify
, the defaults provided here will be used.
Want something for plain old JS? Check out node-retry.
FAQs
Flexible, fault-tolerant operations for Typescript.
The npm package node-endeavour receives a total of 3 weekly downloads. As such, node-endeavour popularity was classified as not popular.
We found that node-endeavour demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.