Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@smithy/util-waiter
Advanced tools
@smithy/util-waiter is a utility package designed to help with implementing waiters in JavaScript applications. Waiters are used to poll for a resource to reach a desired state, which is particularly useful in scenarios involving asynchronous operations or state transitions.
Waiter Configuration
This feature allows you to configure a waiter with specific parameters such as minimum and maximum delay. The `createWaiter` function is used to create a waiter that will poll the `checkState` function until the desired state is reached.
const { createWaiter, WaiterState } = require('@smithy/util-waiter');
const waiterConfig = {
minDelay: 2,
maxDelay: 120,
};
const checkState = async () => {
// Logic to check the state of the resource
return { state: WaiterState.SUCCESS };
};
const waiter = createWaiter(waiterConfig, checkState);
waiter().then(() => console.log('Resource reached the desired state.')).catch((err) => console.error('Failed to reach the desired state:', err));
Custom Retry Logic
This feature allows you to implement custom retry logic by specifying a `retryStrategy` function in the waiter configuration. The `retryStrategy` function determines the delay between retries based on the number of attempts.
const { createWaiter, WaiterState } = require('@smithy/util-waiter');
const waiterConfig = {
minDelay: 2,
maxDelay: 120,
retryStrategy: (attempt) => Math.min(2 ** attempt, 60),
};
const checkState = async () => {
// Logic to check the state of the resource
return { state: WaiterState.RETRY };
};
const waiter = createWaiter(waiterConfig, checkState);
waiter().then(() => console.log('Resource reached the desired state.')).catch((err) => console.error('Failed to reach the desired state:', err));
The `promise-retry` package provides a way to retry a function that returns a promise until it succeeds or a maximum number of retries is reached. It offers customizable retry strategies and is useful for handling transient errors in asynchronous operations. Compared to @smithy/util-waiter, `promise-retry` focuses more on retrying promises rather than waiting for a resource to reach a specific state.
The `async-retry` package is another utility for retrying asynchronous functions. It supports custom retry strategies and can be used to handle retries for various types of asynchronous operations. While similar to `promise-retry`, `async-retry` provides more flexibility in defining retry behavior. Unlike @smithy/util-waiter, it does not specifically focus on waiting for a resource state change.
FAQs
Shared utilities for client waiters for the AWS SDK
The npm package @smithy/util-waiter receives a total of 10,417,067 weekly downloads. As such, @smithy/util-waiter popularity was classified as popular.
We found that @smithy/util-waiter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.