Permalink
Browse files

nextTickOnce for one time call schedule

  • Loading branch information...
medikoo committed Feb 6, 2013
1 parent a5f4dc5 commit f56afc816f0a24732e549d80920e7e2637b305a4
Showing with 29 additions and 1 deletion.
  1. +0 −1 .lint
  2. +16 −0 lib/once.js
  3. +13 −0 test/once.js
View
1 .lint
@@ -12,7 +12,6 @@ jslint_medikoo.predef process, setImmediate, setTimeout
jshint.laxcomma
jshint.camelcase
-jshint.curly
jshint.eqeqeq
jshint.forin
jshint.immed
View
@@ -0,0 +1,16 @@
+'use strict';
+
+var nextTick = require('./next-tick');
+
+module.exports = function (fn) {
+ var scheduled, run;
+ run = function () {
+ scheduled = false;
+ fn();
+ };
+ return function () {
+ if (scheduled) return;
+ scheduled = true;
+ nextTick(run);
+ };
+};
View
@@ -0,0 +1,13 @@
+'use strict';
+
+module.exports = function (t, a, d) {
+ var called = 0, fn = t(function () { ++called; });
+
+ fn();
+ fn();
+ fn();
+ setTimeout(function () {
+ a(called, 1);
+ d();
+ }, 10);
+};

0 comments on commit f56afc8

Please sign in to comment.