
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
Simple Async busy wait module for Node.JS
import {busywait} from 'busywait';
const waitUntil = Date.now() + 2500;
const checkFn = async (iteration: number, delay: number, totalDelay: number): Promise<string> => {
console.log(`Running iteration ${iteration} after delay of ${delay}ms and total delay of ${totalDelay}`);
if (Date.now() > waitUntil) {
return `success`;
}
throw new Error('custom error');
};
(async () => {
const result = await busywait(checkFn, {
sleepTime: 500,
maxChecks: 20,
})
console.log(`Finished after ${result.backoff.time}ms (${result.backoff.iterations} iterations) with result ${result.result}`);
})();
Will result in:
Running iteration 1 after delay of 0ms and total delay of 1
Running iteration 2 after delay of 500ms and total delay of 504
Running iteration 3 after delay of 500ms and total delay of 1007
Running iteration 4 after delay of 500ms and total delay of 1508
Running iteration 5 after delay of 500ms and total delay of 2010
Running iteration 6 after delay of 500ms and total delay of 2511
Finished after 2511ms (6 iterations) with result success
import {busywait} from 'busywait';
const waitUntil = Date.now() + 2500;
const checkFn = async (iteration: number, delay: number, totalDelay: number): Promise<string> => {
console.log(`Running iteration ${iteration} after delay of ${delay}ms and total delay of ${totalDelay}`);
if (Date.now() > waitUntil) {
return `success`;
}
throw new Error('custom error');
};
(async () => {
const result = await busywait(checkFn, {
sleepTime: 100,
jitter: 'none',
multiplier: 2,
})
console.log(`Finished after ${result.backoff.time}ms (${result.backoff.iterations} iterations) with result ${result.result}`);
})();
Will result in:
Running iteration 1 after delay of 0ms and total delay of 1
Running iteration 2 after delay of 100ms and total delay of 104
Running iteration 3 after delay of 200ms and total delay of 306
Running iteration 4 after delay of 400ms and total delay of 707
Running iteration 5 after delay of 800ms and total delay of 1509
Running iteration 6 after delay of 1600ms and total delay of 3110
Finished after 3110ms (6 iterations) with result success
import {busywait} from 'busywait';
const waitUntil = Date.now() + 2500;
const checkFn = async (iteration: number, delay: number, totalDelay: number): Promise<string> => {
console.log(`Running iteration ${iteration} after delay of ${delay}ms and total delay of ${totalDelay}`);
if (Date.now() > waitUntil) {
return `success`;
}
throw new Error('custom error');
};
(async () => {
const result = await busywait(checkFn, {
sleepTime: 100,
jitter: 'full',
multiplier: 2,
waitFirst: true,
})
console.log(`Finished after ${result.backoff.time}ms (${result.backoff.iterations} iterations) with result ${result.result}`);
})();
Will result in:
Running iteration 1 after delay of 31ms and total delay of 31
Running iteration 2 after delay of 165ms and total delay of 199
Running iteration 3 after delay of 217ms and total delay of 417
Running iteration 4 after delay of 378ms and total delay of 796
Running iteration 5 after delay of 1397ms and total delay of 2195
Running iteration 6 after delay of 1656ms and total delay of 3853
Finished after 3853ms (6 iterations) with result success
npm install busywait
A function that takes a single optional argument, which is the current iteration number.
iteration - The current iteration number (starting from 1)delay - The last delay (in ms) that was appliedtotalDelay - The total delay (in ms) applied so farEither:
sleepTime - Time in ms to wait between checks. In the exponential mode, will be the base sleep time.multiplier - The exponential multiplier. Set to 2 or higher to achieve exponential backoff (default: 1 - i.e. linear
backoff)maxDelay - The max delay value between checks in ms (default: infinity)maxChecks - The max number of checks to perform before failing (default: infinity)waitFirst - Should we wait the sleepTime before performing the first check (default: false)jitter - ('none' | 'full') The jitter
mode to use (default: none)failMsg - Custom error message to reject the promise withReturn value is a promise.
checkFn was resolved within a legal number of checks.checkFn rejected (or threw an error) maxChecks times.Promise resolved value:
backoff.iterations - The number of iterations it took to finishbackoff.time - The number of time it took to finishresult - The resolved value of checkFnAll contributions are happily welcomed!
Please make all pull requests to the master branch from your fork and ensure tests pass locally.
FAQs
Async busy wait
The npm package busywait receives a total of 213 weekly downloads. As such, busywait popularity was classified as not popular.
We found that busywait demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.