codekingpro/portable-devtools
114k
1'use strict'
2
3const Dispatcher = require('./dispatcher')
4const RetryHandler = require('../handler/retry-handler')
5
6class RetryAgent extends Dispatcher {
7 #agent = null
8 #options = null
9 constructor (agent, options = {}) {
10 super(options)
11 this.#agent = agent
12 this.#options = options
13 }
14
15 dispatch (opts, handler) {
16 const retry = new RetryHandler({
17 ...opts,
18 retryOptions: this.#options
19 }, {
20 dispatch: this.#agent.dispatch.bind(this.#agent),
21 handler
22 })
23 return this.#agent.dispatch(opts, retry)
24 }
25
26 close () {
27 return this.#agent.close()
28 }
29
30 destroy () {
31 return this.#agent.destroy()
32 }
33}
34
35module.exports = RetryAgent
36 