Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@smithy/util-waiter

Package Overview
Dependencies
3
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @smithy/util-waiter

Shared utilities for client waiters for the AWS SDK


Version published
Maintainers
2
Install size
362 kB
Created

Package description

What is @smithy/util-waiter?

@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.

What are @smithy/util-waiter's main functionalities?

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));

Other packages similar to @smithy/util-waiter

Readme

Source

@smithy/util-waiter

NPM version NPM downloads

An internal package

Usage

You probably shouldn't, at least directly.

FAQs

Last updated on 18 Jun 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc