mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-22 03:46:03 +03:00
add settings
This commit is contained in:
parent
ec6a2cf037
commit
cebec7b154
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@ -1,4 +1,5 @@
|
||||
{
|
||||
"window.autoDetectColorScheme": false,
|
||||
"editor.tabSize": 2,
|
||||
"editor.semanticTokenColorCustomizations":{
|
||||
"enabled": true, // enable semantic highlighting for all themes
|
||||
@ -22,15 +23,15 @@
|
||||
"activityBar.inactiveForeground": "#15202b99",
|
||||
"activityBarBadge.background": "#cfd3ef",
|
||||
"activityBarBadge.foreground": "#15202b",
|
||||
"titleBar.activeBackground": "#5e7959",
|
||||
"titleBar.inactiveBackground": "#5e795999",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveForeground": "#e7e7e799",
|
||||
"statusBarItem.hoverBackground": "#759570",
|
||||
"statusBar.foreground": "#e7e7e7",
|
||||
"activityBar.activeBackground": "#759570",
|
||||
"statusBar.background": "#5e7959",
|
||||
"statusBar.border": "#5e7959",
|
||||
"titleBar.activeBackground": "#5e7959",
|
||||
"titleBar.inactiveBackground": "#5e795999",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveForeground": "#e7e7e799",
|
||||
"titleBar.border": "#5e7959"
|
||||
},
|
||||
"go.languageServerFlags": [],
|
||||
|
@ -82,33 +82,32 @@ func (rb *RequestBreaker) Do(work func(ctx context.Context) (interface{}, error)
|
||||
|
||||
//before
|
||||
fmt.Println("before do : request:", rb.cnter.Total())
|
||||
|
||||
rb.mutex.Lock()
|
||||
//handle status of Open to HalfOpen
|
||||
if rb.state == StateOpen && rb.options.Expiry.Before(time.Now()) {
|
||||
rb.state = StateHalfOpen
|
||||
rb.cnter.Reset()
|
||||
rb.options.OnStateChanged(rb.options.Name, StateOpen, StateHalfOpen)
|
||||
}
|
||||
rb.mutex.Unlock()
|
||||
|
||||
switch rb.state {
|
||||
case StateOpen:
|
||||
return nil, ErrTooManyRequests
|
||||
case StateHalfOpen:
|
||||
//do work from requested user
|
||||
result, err := work(rb.options.Ctx)
|
||||
if err != nil {
|
||||
rb.cnter.Count(FailureState)
|
||||
// result, err := work(rb.options.Ctx)
|
||||
// if err != nil {
|
||||
// rb.cnter.Count(FailureState)
|
||||
// } else {
|
||||
// rb.cnter.Count(SuccessState)
|
||||
// return result, nil
|
||||
// }
|
||||
|
||||
} else {
|
||||
rb.cnter.Count(SuccessState)
|
||||
return result, nil
|
||||
if rb.options.Expiry.Before(time.Now()) {
|
||||
rb.state = StateHalfOpen
|
||||
rb.cnter.Reset()
|
||||
rb.options.OnStateChanged(rb.options.Name, StateOpen, StateHalfOpen)
|
||||
}
|
||||
|
||||
case StateClosed:
|
||||
}
|
||||
|
||||
rb.mutex.Unlock()
|
||||
|
||||
//do work
|
||||
//do work from requested user
|
||||
result, err := work(rb.options.Ctx)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user