[Pkg-javascript-commits] [node-async] 212/480: add AMD support

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:27 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-async.

commit 5a8c60eae25847e77bd22d8b364303ceb9292c03
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date:   Thu Oct 4 06:36:48 2012 -0700

    add AMD support
---
 README.md          | 36 +++++++++++++++++++-----------------
 index.js           |  3 ---
 lib/async.js       | 22 +++++++++++++++-------
 package.json       | 42 +++++++++++++++++++++++-------------------
 test/test-async.js | 30 ++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+), 46 deletions(-)

diff --git a/README.md b/README.md
index 1bbbc47..771bb29 100644
--- a/README.md
+++ b/README.md
@@ -14,23 +14,25 @@ callback as the last argument of your async function.
 
 ## Quick Examples
 
-    async.map(['file1','file2','file3'], fs.stat, function(err, results){
-        // results is now an array of stats for each file
-    });
-
-    async.filter(['file1','file2','file3'], path.exists, function(results){
-        // results now equals an array of the existing files
-    });
-
-    async.parallel([
-        function(){ ... },
-        function(){ ... }
-    ], callback);
-
-    async.series([
-        function(){ ... },
-        function(){ ... }
-    ]);
+```javascript
+async.map(['file1','file2','file3'], fs.stat, function(err, results){
+    // results is now an array of stats for each file
+});
+
+async.filter(['file1','file2','file3'], path.exists, function(results){
+    // results now equals an array of the existing files
+});
+
+async.parallel([
+    function(){ ... },
+    function(){ ... }
+], callback);
+
+async.series([
+    function(){ ... },
+    function(){ ... }
+]);
+```
 
 There are many more functions available so take a look at the docs below for a
 full list. This module aims to be comprehensive, so if you feel anything is
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({

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git



More information about the Pkg-javascript-commits mailing list