Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Created January 20, 2020 10:09
Show Gist options
  • Save Frenchcooc/ef58366b6ec6acf89dfdf39a158be4e7 to your computer and use it in GitHub Desktop.
Save Frenchcooc/ef58366b6ec6acf89dfdf39a158be4e7 to your computer and use it in GitHub Desktop.
// Require the library and client
const circuitBreaker = require("opossum")
const apiClient = require("our-example-api-client")
// Our example request
const getPosts = (req, res, next) => {
// Wrap our client get method in the circuit breaker
const breaker = circuitBreaker(apiClient.get, {
timeout: 3000,
errorThresholdPercentage: 50,
resetTimeout: 5000
})
// Call the API from within the circuit breaker
return breaker
.fire("/api/posts")
.then(res.json)
.catch(next)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment