Skip to content

Commit

Permalink
once: ensure fn is gced
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 3, 2015
1 parent a835c67 commit 4027028
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 4027028

Please sign in to comment.