Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fallback
Advanced tools
Readme
retry a function with a series of arguments until one works
// run this in the repo: `npm install; node sample.js`
// test a list of servers for a response
var fallback = require('fallback')
var request = require('request')
var servers = ['http://foo.baz', 'http://google.com', 'http://fail']
fallback(servers, function (server, callback) {
console.log('trying server at ' + server)
request(server, function (err, response) {
if (err || response.statusCode >= 400) {
// try the next server
return callback()
}
callback(null, response.statusCode)
})
}, function (err, result, server) {
if (err) {
console.error(err)
process.exit(1)
}
if (result) {
console.log('server ' + server + ' returned: ' + result)
} else {
console.log('no servers returned successfully')
}
})
returns
trying server at http://foo.baz
trying server at http://google.com
server http://google.com returned: 200
fallback: (array: Array, iteratorFunction: IteratorFunction, outerCallback: OuterCallback) => void
Call fallback
with an array of alternative values to be used as arguments on
iteratorFunction
.
IteratorFunction: (arrayItem, callback: (err: Error, result) => void) => void
iteratorFunction
is an async function of
function (arrayItem, callback)
, where callback
is a normal node-style
callback(err, result)
continuation. Note that if an error is given to
callback
, the entire fallback sequence will terminate early. This should be
used for unrecoverable errors. To indicate that the operation on the current
arrayItem
did not succeed and that the next one should be tried, callback
should be invoked with a null
error and an undefined
or false
value for
result
. A result
value of null
has the semantics that "the operation
succeeded (and therefore further fallbacks should not be tried), and there
was no result value".
OuterCallback: (err: Error, result, arrayItem, array: Array) => void
In outerCallback
, there are three possible return states:
err
is not undefined: there was an unrecoverable error when executing the
fallback sequence.
result
is false
: none of the fallback alternatives were successful.
arrayItem
is null, and array
contains the original array.
result
is not false
: one of the fallback alternatives was successful.
result
contains the result
value of that operation and arrayItem
contains the value that was used in the successful operation. array
contains the original array.
The parameters for outerCallback
are similar to those in the callback for
Array.prototype.map
- first the value, then an index, then the original
collection.
async.some
?Sort of, but fallback
has much better semantics, and it uses normal
node-style async callbacks (eg, callback(err, result)
) for composability.
with npm
$ npm install fallback
MIT (c) MMXIII jden - Jason Denizac jason@denizac.org http://jden.mit-license.org/2012
FAQs
retry a function with a series of arguments until one works
The npm package fallback receives a total of 185 weekly downloads. As such, fallback popularity was classified as not popular.
We found that fallback 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.