
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
async-wait-until
Advanced tools
Waits until the given predicate function returns a truthy value, then resolves
A lightweight, zero-dependency library for waiting asynchronously until a specific condition is met. Works in any JavaScript environment that supports Promises, including older Node.js versions and browsers (with polyfills if necessary).
For detailed documentation, visit https://devlato.github.io/async-wait-until/
Install using npm:
npm install async-wait-until
The library includes UMD, CommonJS, and ESM bundles, so you can use it in any environment.
import { waitUntil } from 'async-wait-until';
// Example: Wait for an element to appear
await waitUntil(() => document.querySelector('#target') !== null);
import { waitUntil } from 'async-wait-until';
const waitForElement = async () => {
// Wait for an element with the ID "target" to appear
const element = await waitUntil(() => document.querySelector('#target'), { timeout: 5000 });
console.log('Element found:', element);
};
waitForElement();
If the condition is not met within the timeout, a TimeoutError
is thrown.
import { waitUntil, TimeoutError } from 'async-wait-until';
const waitForElement = async () => {
try {
const element = await waitUntil(() => document.querySelector('#target'), { timeout: 5000 });
console.log('Element found:', element);
} catch (error) {
if (error instanceof TimeoutError) {
console.error('Timeout: Element not found');
} else {
console.error('Unexpected error:', error);
}
}
};
waitForElement();
waitUntil(predicate, options)
Waits for the predicate
function to return a truthy value and resolves with that value.
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
predicate | Function | โ Yes | - | A function that returns a truthy value (or a Promise for one). |
options.timeout | number | ๐ซ No | 5000 ms | Maximum wait time before throwing TimeoutError . Use WAIT_FOREVER for no timeout. |
options.intervalBetweenAttempts | number | ๐ซ No | 50 ms | Interval between predicate evaluations. |
Use WAIT_FOREVER
to wait without a timeout:
import { waitUntil, WAIT_FOREVER } from 'async-wait-until';
await waitUntil(() => someCondition, { timeout: WAIT_FOREVER });
Change how often the predicate is evaluated:
await waitUntil(() => someCondition, { intervalBetweenAttempts: 1000 }); // Check every 1 second
Contributions are welcome! To contribute:
npm install
.npm test
npm run lint
npm run format
npm run build
npm run docs
2.0.27
FAQs
Waits until the given predicate function returns a truthy value, then resolves
The npm package async-wait-until receives a total of 76,419 weekly downloads. As such, async-wait-until popularity was classified as popular.
We found that async-wait-until 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.