Constructor
new Throttle(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
object | key value options |
Methods
_isRateBound() → {Boolean}
## _isRateBound
returns true if throttle is bound by rate
Returns:
- Type
- Boolean
_options(options)
## _options
updates options on instance
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | key value object |
Returns:
null
cycle(request)
## cycle
an iterator of sorts. Should be called when
- something added to throttle (check if it can be sent immediately)
- `ratePer` ms have elapsed since nth last call where n is `rate` (may have
available rate)
- some request has ended (may have available concurrency)
Parameters:
Name | Type | Description |
---|---|---|
request |
Request | the superagent request |
Returns:
null
next() → {Boolean}
## next
checks whether instance has available capacity and calls throttle.send()
Returns:
- Type
- Boolean
options(options, valueopt)
## options
thin wrapper for _options
* calls `this.cycle()`
* adds alternate syntax
alternate syntax:
throttle.options('active', true)
throttle.options({active: true})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object | either key value object or keyname | |
value |
Mixed |
<optional> |
value for key |
Returns:
null
plugin(serial)
## plugin
`superagent` `use` function should refer to this plugin method a la
`.use(throttle.plugin())`
mask the original `.end` and store the callback passed in
Parameters:
Name | Type | Description |
---|---|---|
serial |
string | any string is ok, it's just a namespace |
Returns:
null
send(request)
## send
sends a queued request.
Parameters:
Name | Type | Description |
---|---|---|
request |
Request | superagent request |
Returns:
null
serial(request, state)
## serial
updates throttle.\_serials and throttle.\_isRateBound
serial subthrottles allow some requests to be serialised, whilst maintaining
their place in the queue. The _serials structure keeps track of what serial
queues are waiting for a response.
```
throttle._serials = {
'example.com/end/point': true,
'example.com/another': false
}
```
Parameters:
Name | Type | Description |
---|---|---|
request |
Request | superagent request |
state |
Boolean | new state for serial |