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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @scoir/async-throttler

      Weekly Downloads

      31

      Version

      3.0.1

      License

      UNLICENSED

      Unpacked Size

      9.87 kB

      Total Files

      7

      Last publish

      Collaborators

      • jat-scoir
      • jasonblanchard
      • jaymi_johnson
      • jspencer_scoir
      • scoir-kevinrathgeber
      • smclaughlin-scoir
      • sbeyers
      • eriksuman
      • robelder
      • scoir-alexr
      • cbartlett33
      • cmccrory
      • ahagner
      • ccarson_scoir
      • scoir-dev
      • daynek
      • pjohnson11120
      • gakhvledi
      • thos-scoir
      • scoir-devops