-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
36 lines (24 loc) · 1005 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var Assert = require('assert');
var Breaker = require('./lib/breaker');
var Stats = require('./lib/stats');
exports.Breaker = Breaker;
exports.Stats = Stats;
exports.createBreaker = function createBreaker(impl, options) {
if (typeof impl === 'function') {
impl = { execute: impl };
}
return new Breaker(impl, options);
};
exports.createStats = function createStats(command, options) {
var stats;
Assert.ok(command instanceof Breaker, 'Stats can only be created for Breaker instances.');
stats = new Stats(options);
command.on('execute', stats.increment.bind(stats, 'executions'));
command.on('reject', stats.increment.bind(stats, 'rejections'));
command.on('success', stats.increment.bind(stats, 'successes'));
command.on('failure', stats.increment.bind(stats, 'failures'));
command.on('timeout', stats.increment.bind(stats, 'timeouts'));
command.on('duration', stats.sample.bind(stats, 'duration'));
return stats;
};