Created
October 23, 2021 18:57
-
-
Save oleh-zaporozhets/b27e4ddc69d63bda2afa85405ef5a7c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestHttp extends Http { | |
constructor() { | |
super('http://localhost:5000/'); | |
} | |
public test() { | |
return this.instance.get('/test'); | |
} | |
} | |
async function main() { | |
const testHttp = new TestHttp(); | |
const errorHandler = (err: AxiosError) => { | |
console.log(err.message); | |
return err?.response?.status === 429; | |
}; | |
const testCircuitBreaker = new CircuitBreakerWithEmitter(testHttp, { | |
timeout: 10_000, | |
errorHandler, | |
}); | |
testCircuitBreaker.on('OPEN', () => { | |
console.log('CIRCUIT BREAKER WAS OPENED'); | |
}); | |
testCircuitBreaker.on('CLOSE', async () => { | |
console.log('CIRCUIT BREAKER WAS CLOSED'); | |
}); | |
setInterval(() => { | |
testHttp.test().catch(() => {}); | |
}, 2000); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment