retry-agent.js 684 B

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