Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scoir/async-throttler

Package Overview
Dependencies
Maintainers
36
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scoir/async-throttler

This utility will delay the resolution of a promise until a delay has elapsed. It also exposes state of the passed promise so that ui events can be keyed off that.

  • 3.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
43
increased by126.32%
Maintainers
36
Weekly downloads
 
Created
Source

Async Throttler

This utility will delay the resolution of a promise until a delay has elapsed. It also exposes state of the passed promise so that ui events can be keyed off that.

Usage - AsyncThrottler

create

Pass in your state update handler so that you can receive throttler updates. Returns a throttler instance

import asyncThrottler from '@scoir/async-throttler';

class ExampleComp extends React.Component {
    componentWillMount () {
        this.throttler = asyncThrottler.create(state => this.setState(state))
    }
    ...
}

state update handler

When the throttler state changes, it will execute the callback that was passed into the create function. That object looks like this:

{
    isProcessing: <boolean>,
    isProcessed: <boolean>,
    isComplete: <boolean>,
    isError: <boolean>,
}

Usage - throttler instance

execute

Pass in the promise you would like to throttle and an optional delay (default is 700ms)

this.throttler.execute(this.doAsync());
this.throttler.execute(this.doAsync(), 1000);

reset

Restores the throttler instance state back to its initial state.

this.throttler.reset();
{
    isProcessing: false,
    isProcessed: false,
    isComplete: false,
    isError: false,
}

FAQs

Package last updated on 24 Jan 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc