Skip to content

Commit

Permalink
fix: ensure fallback event emits after function call
Browse files Browse the repository at this point in the history
  • Loading branch information
lance committed Dec 22, 2016
1 parent 38f4f8d commit df40ea7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Here is an example using [hapi.js](hapijs.com). See the
[examples](https://github.com/bucharest-gold/opossum/tree/master/examples/)
folder for more detail.

```js index.js
```js
// server.js
const server = new Hapi.Server();
server.register(require('inert', (err) => possibleError(err)));
server.route({
Expand All @@ -87,7 +88,7 @@ server.route({
});
```

```html index.html
```html
<html>
<head>
<title>My Super App</title>
Expand All @@ -101,7 +102,8 @@ server.route({
</html>
```

```js app.js
```js
// app.js
const route = 'https://example-service.com/rest/route';
const circuitBreakerOptions = {
timeout: 500,
Expand Down
2 changes: 1 addition & 1 deletion lib/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ function fail (circuit, err, args) {

if (circuit[FALLBACK_FUNCTION]) {
return new circuit.Promise((resolve, reject) => {
const result = circuit[FALLBACK_FUNCTION].apply(circuit[FALLBACK_FUNCTION], args);
/**
* Emitted when the breaker executes a fallback function
* @event CircuitBreaker#fallback
*/
circuit.emit('fallback', result);
const result = circuit[FALLBACK_FUNCTION].apply(circuit[FALLBACK_FUNCTION], args);
resolve(result);
});
}
Expand Down

0 comments on commit df40ea7

Please sign in to comment.