go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/breaker/docs.go (about)

     1  /*
     2  Package breaker provides a circuitbraker mechanism for dealing with flaky or unreliable counterparties.
     3  
     4  The algorithm used for the state machine is described by Microsoft https://docs.microsoft.com/en-us/previous-versions/msp-n-p/dn589784(v=pandp.10)
     5  
     6  An example of using a circuit breaker for an http call might be:
     7  
     8  	    b := circuitbreaker.New[string, *http.Response](circuitbreaker.Config{})
     9  		phoneHome := b.Intercept(async.ActionerFunc(func(ctx context.Context, url string) (*http.Response, error) {
    10  			return http.DefaultClient.Do(http.NewRequestWithContext(ctx, http.VerbGet, url, nil))
    11  	    })
    12  
    13  In the above, `phoneHome` now will be wrapped with circuit breaker mechanics. You would call it with `phoneHome.Action(ctx, nil)` etc.
    14  */
    15  package breaker // import "go.charczuk.com/sdk/breaker"