Skip to content

Commit

Permalink
[timers] Use asap.js
Browse files Browse the repository at this point in the history
  • Loading branch information
juandopazo committed Jan 22, 2014
1 parent 4ed6edb commit afb8b66
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 92 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"main": "./index.js",
"dependencies": {
"request": "~2.21.0"
"request": "~2.21.0",
"asap": "~1.0.0"
},
"devDependencies": {
"yogi": "~0.1.0",
Expand Down
7 changes: 5 additions & 2 deletions src/timers/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"builds": {
"timers": {
"jsfiles": [
"js/timers.js"
"prologue.js",
"../../../node_modules/asap/queue.js",
"../../../node_modules/asap/asap.js",
"epilogue.js"
]
}
},
"name": "timers"
}
}
40 changes: 40 additions & 0 deletions src/timers/js/epilogue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
Y.soon accepts a callback function. The callback function will be called
once in a future turn of the JavaScript event loop. If the function
requires a specific execution context or arguments, wrap it with Y.bind.
Y.soon returns an object with a cancel method. If the cancel method is
called before the callback function, the callback function won't be
called.
@method soon
@for YUI
@param {Function} callbackFunction
@return {Object} An object with a cancel method. If the cancel method is
called before the callback function, the callback function won't be
called.
**/
function soon(callbackFunction) {
var canceled;

soon._asynchronizer(function () {
// Some asynchronizers may provide their own cancellation
// methods such as clearImmediate or clearTimeout but some
// asynchronizers do not. For simplicity, cancellation is
// entirely handled here rather than wrapping the other methods.
// All asynchronizers are expected to always call this anonymous
// function.
if (!canceled) {
callbackFunction();
}
});

return {
cancel: function () {
canceled = 1;
}
};
}

soon._asynchronizer = asap;

Y.soon = soon;
13 changes: 13 additions & 0 deletions src/timers/js/prologue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Provides utilities for timed asynchronous callback execution.
* Y.soon is a setImmediate/process.nextTick/setTimeout wrapper.
*
* @module timers
* @author Steven Olmsted
*/
var module = {},
global = Y.config.global;

function require(mod) {
return Queue;
}
89 changes: 0 additions & 89 deletions src/timers/js/timers.js

This file was deleted.

0 comments on commit afb8b66

Please sign in to comment.