-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5588a1d
commit 04c8acb
Showing
3 changed files
with
23 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
'use strict' | ||
|
||
const Dispatcher = require('../dispatcher/dispatcher') | ||
const RetryHandler = require('../handler/retry-handler') | ||
|
||
class RetryDispatcher extends Dispatcher { | ||
#dispatcher | ||
#opts | ||
|
||
constructor (dispatcher, opts) { | ||
super() | ||
|
||
this.#dispatcher = dispatcher | ||
this.#opts = opts | ||
} | ||
|
||
dispatch (opts, handler) { | ||
opts.retryOptions = { ...this.#opts, ...opts.retryOptions } | ||
|
||
return this.#dispatcher.dispatch( | ||
opts, | ||
new RetryHandler(opts, { | ||
handler, | ||
dispatch: this.#dispatcher.dispatch.bind(this.#dispatcher) | ||
}) | ||
) | ||
module.exports = globalOpts => { | ||
return dispatcher => { | ||
const bindedDispatch = dispatcher.dispatch.bind(dispatcher) | ||
|
||
return function retryInterceptor (opts, handler) { | ||
opts.retryOptions = { ...globalOpts, ...opts.retryOptions } | ||
|
||
return bindedDispatch( | ||
opts, | ||
new RetryHandler(opts, { | ||
handler, | ||
dispatch: bindedDispatch | ||
}) | ||
) | ||
} | ||
} | ||
|
||
close (...args) { | ||
return this.#dispatcher.close(...args) | ||
} | ||
|
||
destroy (...args) { | ||
return this.#dispatcher.destroy(...args) | ||
} | ||
} | ||
|
||
module.exports = opts => { | ||
return dispatcher => new RetryDispatcher(dispatcher, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters