@scoir/async-throttler

3.0.1 • Public • Published

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,
}

Readme

Keywords

none

Package Sidebar

Install

npm i @scoir/async-throttler

Weekly Downloads

43

Version

3.0.1

License

UNLICENSED

Unpacked Size

9.87 kB

Total Files

7

Last publish

Collaborators

  • jasonblanchard
  • alittletonscoir
  • rocky.egawa
  • eric.kertzscoir
  • bonsebas
  • brynkng
  • azragal
  • jhudzik
  • jaymi_johnson
  • jspencer_scoir
  • dkozicki
  • scoir-kevinrathgeber
  • sully-scoir
  • smclaughlin-scoir
  • sbeyers
  • eriksuman
  • robelder
  • scoir-alexr
  • danancook
  • dmscoir
  • cbartlett33
  • jpshrader
  • cmccrory
  • ahagner
  • rrosenthal
  • cellisscoir
  • dbyler_scoir
  • mvannucciscoir
  • kjbillings
  • ccarson_scoir
  • scoir-dev
  • daynek
  • pjohnson11120
  • gakhvledi
  • thos-scoir
  • scoir-devops