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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.0-beta.b0e6db420canary
3.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.11
3.0.030
3.0.0-beta.b0e6db420
3.0.0-beta.ed1625900
2.0.10
2.0.00
1.0.20
1.0.10
1.0.00

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