add settings

This commit is contained in:
eamon 2020-05-28 12:29:45 +08:00
parent ec6a2cf037
commit cebec7b154
2 changed files with 19 additions and 19 deletions

View File

@ -1,4 +1,5 @@
{ {
"window.autoDetectColorScheme": false,
"editor.tabSize": 2, "editor.tabSize": 2,
"editor.semanticTokenColorCustomizations":{ "editor.semanticTokenColorCustomizations":{
"enabled": true, // enable semantic highlighting for all themes "enabled": true, // enable semantic highlighting for all themes
@ -22,15 +23,15 @@
"activityBar.inactiveForeground": "#15202b99", "activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#cfd3ef", "activityBarBadge.background": "#cfd3ef",
"activityBarBadge.foreground": "#15202b", "activityBarBadge.foreground": "#15202b",
"titleBar.activeBackground": "#5e7959",
"titleBar.inactiveBackground": "#5e795999",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799",
"statusBarItem.hoverBackground": "#759570", "statusBarItem.hoverBackground": "#759570",
"statusBar.foreground": "#e7e7e7", "statusBar.foreground": "#e7e7e7",
"activityBar.activeBackground": "#759570", "activityBar.activeBackground": "#759570",
"statusBar.background": "#5e7959", "statusBar.background": "#5e7959",
"statusBar.border": "#5e7959", "statusBar.border": "#5e7959",
"titleBar.activeBackground": "#5e7959",
"titleBar.inactiveBackground": "#5e795999",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799",
"titleBar.border": "#5e7959" "titleBar.border": "#5e7959"
}, },
"go.languageServerFlags": [], "go.languageServerFlags": [],

View File

@ -82,33 +82,32 @@ func (rb *RequestBreaker) Do(work func(ctx context.Context) (interface{}, error)
//before //before
fmt.Println("before do : request:", rb.cnter.Total()) fmt.Println("before do : request:", rb.cnter.Total())
rb.mutex.Lock() 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 { switch rb.state {
case StateOpen: case StateOpen:
return nil, ErrTooManyRequests return nil, ErrTooManyRequests
case StateHalfOpen: case StateHalfOpen:
//do work from requested user //do work from requested user
result, err := work(rb.options.Ctx) // result, err := work(rb.options.Ctx)
if err != nil { // if err != nil {
rb.cnter.Count(FailureState) // rb.cnter.Count(FailureState)
// } else {
// rb.cnter.Count(SuccessState)
// return result, nil
// }
} else { if rb.options.Expiry.Before(time.Now()) {
rb.cnter.Count(SuccessState) rb.state = StateHalfOpen
return result, nil rb.cnter.Reset()
rb.options.OnStateChanged(rb.options.Name, StateOpen, StateHalfOpen)
} }
case StateClosed: case StateClosed:
} }
rb.mutex.Unlock()
//do work
//do work from requested user //do work from requested user
result, err := work(rb.options.Ctx) result, err := work(rb.options.Ctx)