Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@jcoreio/poll
Advanced tools
yet another promise-based poller (I didn't like the API design of others out there)
npm install --save @jcoreio/poll
const poll = require('@jcoreio/poll')
const superagent = require('superagent')
poll(() => superagent.get('http://google.com'), 1000)
.timeout(30000)
.then(() => console.log("You're connected to the internet!"))
poll(fn, interval, [options])
Begins calling fn
every interval
milliseconds until the condition passes
(which defaults to fn
didn't throw an Error
or return a rejected Promise
).
Returns a Promise
that resolves when polling finishes or fails, which may be:
fn
calls the pass
method provided to itfn
calls the fail
method provided to itfn
returns/resolves to a value or throws/rejects with an Error
that
passes the conditionpoll
times out waiting for any of the abovefn
will be called with a context object:
{
attemptNumber: number, // the number of this call (starting from 0)
elapsedTime: number, // the number of milliseconds since polling started
pass: (value: any) => void, // makes `poll` resolve immediately with this value
fail: (error: Error) => void, // makes `poll` reject immediately with this Error
}
You can change the condition by calling .until
on the returned Promise
:
poll(...).until((error, result) => result > 3)
error
will be the Error
from the last call to fn
(if it rejected or threw)
and result
will be the value it resolved to or returned otherwise.
You can specify a timeout (in milliseconds) by calling .timeout
on the returned Promise
:
poll(...).timeout(30000) // time out after 30 seconds
If you call .noWrapError()
on the returned Promise
, it won't wrap rejection errors.
FAQs
handy promised-based polling API
We found that @jcoreio/poll demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.