From 78ae8f69547fb498c928492134e2c90060ec6081 Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 14 May 2020 23:35:44 +0800 Subject: [PATCH] update update contents --- .vscode/settings.json | 3 ++- resiliency/06_circuit_breaker/circuit_breaker.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 06accc2..462a89a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -47,6 +47,7 @@ }, "fileheader.Author":"Edward", "fileheader.tpl": "/*\r\n * @Description: https://github.com/crazybber\r\n * @Author: {author}\r\n * @Date: {createTime}\r\n * @Last Modified by: {lastModifiedBy}\r\n * @Last Modified time: {updateTime}\r\n */\r\n\r\n", -"fileheader.LastModifiedBy": "Edward" +"fileheader.LastModifiedBy": "Edward", +"peacock.color": "#5e7959" } //https://vscode.readthedocs.io/en/latest/getstarted/settings/ diff --git a/resiliency/06_circuit_breaker/circuit_breaker.go b/resiliency/06_circuit_breaker/circuit_breaker.go index b40a039..476ea03 100644 --- a/resiliency/06_circuit_breaker/circuit_breaker.go +++ b/resiliency/06_circuit_breaker/circuit_breaker.go @@ -70,6 +70,16 @@ func NewRequestBreaker(opts ...Option) *RequestBreaker { } } +// Do runs the given request if the RequestBreaker accepts it. +// Do returns an error instantly if the RequestBreaker rejects the request. +// Otherwise, Execute returns the result of the request. +// If a panic occurs in the request, the RequestBreaker handles it as an error and causes the same panic again. +func (rb *RequestBreaker) Do(req func() (interface{}, error)) (interface{}, error) { + + result, err := req() + return result, err +} + //State of current switch type State int