Skip to content

Instantly share code, notes, and snippets.

@wilsonpage
Last active December 20, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilsonpage/6166644 to your computer and use it in GitHub Desktop.
Save wilsonpage/6166644 to your computer and use it in GitHub Desktop.
'use strict';
/**
* Module Dependencies
*/
var raf = require('../device/raf');
/**
* Locals
*/
var tasks = [];
/**
* Exports
*/
exports = module.exports = function(fn) {
var isFirst = !tasks.length;
// Wrap the function in a
// function that schedules
// the next task in the list, as
// well as calling the function
var _fn = function() {
var next = tasks.shift();
if (next) raf(next);
fn();
};
// Push it on the stack
tasks.push(_fn);
// If this is the
// first task kick off
// the chain of rAF calls
if (isFirst) raf(_fn);
};
// TODO
exports.remove = function(fn) {
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment