[d24f17c] | 1 | # Class: BalancedPool
|
---|
| 2 |
|
---|
| 3 | Extends: `undici.Dispatcher`
|
---|
| 4 |
|
---|
| 5 | A pool of [Pool](Pool.md) instances connected to multiple upstreams.
|
---|
| 6 |
|
---|
| 7 | Requests are not guaranteed to be dispatched in order of invocation.
|
---|
| 8 |
|
---|
| 9 | ## `new BalancedPool(upstreams [, options])`
|
---|
| 10 |
|
---|
| 11 | Arguments:
|
---|
| 12 |
|
---|
| 13 | * **upstreams** `URL | string | string[]` - It should only include the **protocol, hostname, and port**.
|
---|
| 14 | * **options** `BalancedPoolOptions` (optional)
|
---|
| 15 |
|
---|
| 16 | ### Parameter: `BalancedPoolOptions`
|
---|
| 17 |
|
---|
| 18 | Extends: [`PoolOptions`](Pool.md#parameter-pooloptions)
|
---|
| 19 |
|
---|
| 20 | * **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
---|
| 21 |
|
---|
| 22 | The `PoolOptions` are passed to each of the `Pool` instances being created.
|
---|
| 23 | ## Instance Properties
|
---|
| 24 |
|
---|
| 25 | ### `BalancedPool.upstreams`
|
---|
| 26 |
|
---|
| 27 | Returns an array of upstreams that were previously added.
|
---|
| 28 |
|
---|
| 29 | ### `BalancedPool.closed`
|
---|
| 30 |
|
---|
| 31 | Implements [Client.closed](Client.md#clientclosed)
|
---|
| 32 |
|
---|
| 33 | ### `BalancedPool.destroyed`
|
---|
| 34 |
|
---|
| 35 | Implements [Client.destroyed](Client.md#clientdestroyed)
|
---|
| 36 |
|
---|
| 37 | ### `Pool.stats`
|
---|
| 38 |
|
---|
| 39 | Returns [`PoolStats`](PoolStats.md) instance for this pool.
|
---|
| 40 |
|
---|
| 41 | ## Instance Methods
|
---|
| 42 |
|
---|
| 43 | ### `BalancedPool.addUpstream(upstream)`
|
---|
| 44 |
|
---|
| 45 | Add an upstream.
|
---|
| 46 |
|
---|
| 47 | Arguments:
|
---|
| 48 |
|
---|
| 49 | * **upstream** `string` - It should only include the **protocol, hostname, and port**.
|
---|
| 50 |
|
---|
| 51 | ### `BalancedPool.removeUpstream(upstream)`
|
---|
| 52 |
|
---|
| 53 | Removes an upstream that was previously addded.
|
---|
| 54 |
|
---|
| 55 | ### `BalancedPool.close([callback])`
|
---|
| 56 |
|
---|
| 57 | Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise).
|
---|
| 58 |
|
---|
| 59 | ### `BalancedPool.destroy([error, callback])`
|
---|
| 60 |
|
---|
| 61 | Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
---|
| 62 |
|
---|
| 63 | ### `BalancedPool.connect(options[, callback])`
|
---|
| 64 |
|
---|
| 65 | See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback).
|
---|
| 66 |
|
---|
| 67 | ### `BalancedPool.dispatch(options, handlers)`
|
---|
| 68 |
|
---|
| 69 | Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
---|
| 70 |
|
---|
| 71 | ### `BalancedPool.pipeline(options, handler)`
|
---|
| 72 |
|
---|
| 73 | See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler).
|
---|
| 74 |
|
---|
| 75 | ### `BalancedPool.request(options[, callback])`
|
---|
| 76 |
|
---|
| 77 | See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
---|
| 78 |
|
---|
| 79 | ### `BalancedPool.stream(options, factory[, callback])`
|
---|
| 80 |
|
---|
| 81 | See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
---|
| 82 |
|
---|
| 83 | ### `BalancedPool.upgrade(options[, callback])`
|
---|
| 84 |
|
---|
| 85 | See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback).
|
---|
| 86 |
|
---|
| 87 | ## Instance Events
|
---|
| 88 |
|
---|
| 89 | ### Event: `'connect'`
|
---|
| 90 |
|
---|
| 91 | See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect).
|
---|
| 92 |
|
---|
| 93 | ### Event: `'disconnect'`
|
---|
| 94 |
|
---|
| 95 | See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect).
|
---|
| 96 |
|
---|
| 97 | ### Event: `'drain'`
|
---|
| 98 |
|
---|
| 99 | See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain).
|
---|