diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | index.js | 3 | ||||
-rw-r--r-- | lib/async.js | 22 | ||||
-rw-r--r-- | package.json | 42 | ||||
-rw-r--r-- | test/test-async.js | 30 |
5 files changed, 69 insertions, 30 deletions
@@ -14,7 +14,7 @@ callback as the last argument of your async function. ## Quick Examples -```js +```javascript async.map(['file1','file2','file3'], fs.stat, function(err, results){ // results is now an array of stats for each file }); diff --git a/index.js b/index.js deleted file mode 100644 index 8e23845..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// This file is just added for convenience so this repository can be -// directly checked out into a project's deps folder -module.exports = require('./lib/async'); diff --git a/lib/async.js b/lib/async.js index 7cc4f5e..bbbd05c 100644 --- a/lib/async.js +++ b/lib/async.js @@ -7,13 +7,6 @@ var root = this, previous_async = root.async; - if (typeof module !== 'undefined' && module.exports) { - module.exports = async; - } - else { - root.async = async; - } - async.noConflict = function () { root.async = previous_async; return async; @@ -689,4 +682,19 @@ }; }; + // AMD / RequireJS + if (typeof define !== 'undefined' && define.amd) { + define('async', [], function () { + return async; + }); + } + // Node.js + else if (typeof module !== 'undefined' && module.exports) { + module.exports = async; + } + // included directly via <script> tag + else { + root.async = async; + } + }()); diff --git a/package.json b/package.json index 39bc4ff..253e46e 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,25 @@ -{ "name": "async" -, "description": "Higher-order functions and common patterns for asynchronous code" -, "main": "./index" -, "author": "Caolan McMahon" -, "version": "0.1.22" -, "repository" : - { "type" : "git" - , "url" : "http://github.com/caolan/async.git" - } -, "bugs" : { "url" : "http://github.com/caolan/async/issues" } -, "licenses" : - [ { "type" : "MIT" - , "url" : "http://github.com/caolan/async/raw/master/LICENSE" +{ + "name": "async", + "description": "Higher-order functions and common patterns for asynchronous code", + "main": "./lib/async", + "author": "Caolan McMahon", + "version": "0.1.23", + "repository" : { + "type" : "git", + "url" : "http://github.com/caolan/async.git" + }, + "bugs" : { + "url" : "http://github.com/caolan/async/issues" + }, + "licenses" : [ + { + "type" : "MIT", + "url" : "http://github.com/caolan/async/raw/master/LICENSE" + } + ], + "devDependencies": { + "nodeunit": ">0.0.0", + "uglify-js": "1.2.x", + "nodelint": ">0.0.0" } - ] -, "devDependencies": - { "nodeunit": ">0.0.0" - , "uglify-js": "1.2.x" - , "nodelint": ">0.0.0" - } } diff --git a/test/test-async.js b/test/test-async.js index 52f5536..39ec47d 100644 --- a/test/test-async.js +++ b/test/test-async.js @@ -101,6 +101,36 @@ exports['auto'] = function(test){ }); }; +exports['auto petrify'] = function (test) { + var callOrder = []; + async.auto({ + task1: ['task2', function (callback) { + setTimeout(function () { + callOrder.push('task1'); + callback(); + }, 100); + }], + task2: function (callback) { + setTimeout(function () { + callOrder.push('task2'); + callback(); + }, 200); + }, + task3: ['task2', function (callback) { + callOrder.push('task3'); + callback(); + }], + task4: ['task1', 'task2', function (callback) { + callOrder.push('task4'); + callback(); + }] + }, + function (err) { + test.same(callOrder, ['task2', 'task3', 'task1', 'task4']); + test.done(); + }); +}; + exports['auto results'] = function(test){ var callOrder = []; async.auto({ |