Skip to content

Commit

Permalink
Merge pull request #831 from megawac/pedantic-once
Browse files Browse the repository at this point in the history
once: ensure fn is gced
  • Loading branch information
aearly committed Jul 2, 2015
2 parents 6364921 + ab4157d commit f4c6e67
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@
};

function only_once(fn) {
var called = false;
return function() {
if (called) throw new Error("Callback was already called.");
called = true;
if (fn === null) throw new Error("Callback was already called.");
fn.apply(this, arguments);
fn = null;
};
}

function _once(fn) {
var called = false;
return function() {
if (called) return;
called = true;
if (fn === null) return;
fn.apply(this, arguments);
fn = null;
};
}

Expand Down

0 comments on commit f4c6e67

Please sign in to comment.