Socket
Socket
Sign inDemoInstall

@scoir/async-throttler

Package Overview
Dependencies
0
Maintainers
36
Versions
9
Alerts
File Explorer

Advanced tools

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.


Version published
Weekly downloads
149
increased by93.51%
Maintainers
36
Created
Weekly downloads
 

Readme

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

Last updated on 24 Jan 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