Skip to content

Commit

Permalink
[dist] 0.0.7
Browse files Browse the repository at this point in the history
* Small fix in timers, cant stop twice
  • Loading branch information
dscape committed Nov 12, 2012
1 parent 66ca3d6 commit 875acae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/lynx.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ util.inherits(Lynx, Stream);
Lynx.prototype.createTimer = function createTimer(stat, sample_rate) {
var self = this
, start_time = new Date ().getTime()
, stopped = false
;

//
Expand All @@ -116,8 +117,31 @@ Lynx.prototype.createTimer = function createTimer(stat, sample_rate) {
// Check example above
//
function stop() {
//
// If timer is already stopped just ignore the request
//
if(stopped) {
self.on_error(
{ message : "Can't stop a timer twice"
, f : 'stop'
});
return;
}

//
// Calculate duration
//
var duration = new Date ().getTime() - start_time;

//
// Emit
//
self.timing(stat, duration, sample_rate);

//
// So no one stops a timer twice (causing two emits)
//
stopped = true;
}

//
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "name" : "lynx"
, "description" : "Minimalistic StatsD client for Node.js programs"
, "version" : "0.0.6"
, "version" : "0.0.7"
, "author" : "Lloyd Hilaiel"
, "contributors": [ "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" ]
, "scripts" : { "test": "tap tests/*-test.js" }
Expand Down
10 changes: 10 additions & 0 deletions tests/timings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ macros.matchFixturesTest('timings', function runTest(connection) {
// Stop the timer
//
timer.stop();

//
// Atempt to stop already stopped timer
// Will console.log `Can't stop a timer twice`
//
// We are not testing for this, cause its just an error message
// but this would be raised on scenarios where a more strict error handler
// is enforced by the user
//
second_timer.stop();
}, 200);

//
Expand Down

0 comments on commit 875acae

Please sign in to comment.