
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Sets a minimum delay before a callback can be called, no matter how long it takes for the caller to call it.
Pronounced as one word. Sets a minimum delay before a callback can be called, no matter how long it takes for the caller to call it.
function mindelay(function callback, number delayMS)
// Adds a minimum delay in milliseconds to a callback, however long the caller takes to call it.
// Returns callback wrapped with delay code.
// If the wrapped callback is called before the delay is expired, it still waits until the end of the delay.
// If the wrapped callback is called after the delay is expired, it executes immediately.
// wrappedCallback.call always contains the original callback, if you need to call it directly with no delay.
// Alternatively, calling wrappedCallback.cancel() will cancel any delay, so that next time you call the wrapped callback it will execute immediately.
//
// If arguments callback, delayMS are reversed, it'll still work fine.
// An exception is thrown if arguments have incorrect types.
//
On command line:
$ npm install --save mindelay
In NodeJS:
let mindelay = require('mindelay');
Alternatively, in browser JavaScript:
<script src="path/to/mindelay.js"></script>
We're using the usecase of an API response, which illustrates the utility of mindelay
best
and is how we use mindelay
in production.
Instead of something like this, which responds as soon as the API responds
apiCall(data, function(response){
//blah
});
or something like this, which adds a fixed delay of one second to the API response time, no matter how long the API response time
apiCall(data, function(response){
setTimeout(function(){
//blah
}, 1000)
});
use something like this, which delays by at least one second, but if the API takes a long while it will respond as soon as possible.
apiCall(data, mindelay(function(response){
//blah
}, 1000));
var wrappedCallback = mindelay(function(response){
//blah
}, 1000));
If you ever need to reference the callback directly, use wrappedCallback.call
:
wrappedCallback.call(/*...*/) //will have no delay
If you want to cancel any delay on a wrapped callback, use wrappedCallback.cancel
:
wrappedCallback.cancel()
wrappedCallback() //will have no delay
Pictured is a chatbot (SkillFlow) that needs to make a query to a Natural Language Processing API before it's able to respond.
We want to add a somewhat natural delay, but must keep in mind that the API may take any amount of time to respond, and
we can't just use setTimeout
and keep the user waiting for extra long.
The solution is of course to use mindelay
instead of setTimeout
.
Copyright ©2016 SkillFlow. MIT License. Created by Clive Chan, with contributions from David Tesler.
FAQs
Sets a minimum delay before a callback can be called, no matter how long it takes for the caller to call it.
The npm package mindelay receives a total of 0 weekly downloads. As such, mindelay popularity was classified as not popular.
We found that mindelay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.