Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@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 4,189,236 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 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.