Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
85 lines
2.9 KiB
Plaintext
85 lines
2.9 KiB
Plaintext
# Agent
|
|
|
|
Extends: `undici.Dispatcher`
|
|
|
|
Agent allows dispatching requests against multiple different origins.
|
|
|
|
Requests are not guaranteed to be dispatched in order of invocation.
|
|
|
|
## `new undici.Agent([options])`
|
|
|
|
Arguments:
|
|
|
|
* **options** `AgentOptions` (optional)
|
|
|
|
Returns: `Agent`
|
|
|
|
### Parameter: `AgentOptions`
|
|
|
|
Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
|
|
|
|
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
|
* **maxOrigins** `number` (optional) - Default: `Infinity` - Limits the total number of origins that can receive requests at a time, throwing an `MaxOriginsReachedError` error when attempting to dispatch when the max is reached. If `Infinity`, no limit is enforced.
|
|
|
|
## Instance Properties
|
|
|
|
### `Agent.closed`
|
|
|
|
Implements [Client.closed](/docs/docs/api/Client.md#clientclosed)
|
|
|
|
### `Agent.destroyed`
|
|
|
|
Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed)
|
|
|
|
## Instance Methods
|
|
|
|
### `Agent.close([callback])`
|
|
|
|
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
|
|
### `Agent.destroy([error, callback])`
|
|
|
|
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
|
|
### `Agent.dispatch(options, handler: AgentDispatchOptions)`
|
|
|
|
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
|
|
#### Parameter: `AgentDispatchOptions`
|
|
|
|
Extends: [`DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dispatchoptions)
|
|
|
|
* **origin** `string | URL`
|
|
|
|
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
|
|
### `Agent.connect(options[, callback])`
|
|
|
|
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
|
|
### `Agent.dispatch(options, handler)`
|
|
|
|
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
|
|
### `Agent.pipeline(options, handler)`
|
|
|
|
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
|
|
### `Agent.request(options[, callback])`
|
|
|
|
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
|
|
### `Agent.stream(options, factory[, callback])`
|
|
|
|
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
|
|
### `Agent.upgrade(options[, callback])`
|
|
|
|
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
|
|
### `Agent.stats()`
|
|
|
|
Returns an object of stats by origin in the format of `Record<string, TClientStats | TPoolStats>`
|
|
|
|
See [`PoolStats`](/docs/docs/api/PoolStats.md) and [`ClientStats`](/docs/docs/api/ClientStats.md).
|