[Pkg-javascript-commits] [node-after] 01/05: New upstream version 0.8.2

Sruthi Chandran srud-guest at moszumanska.debian.org
Sat Dec 10 17:16:40 UTC 2016


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

srud-guest pushed a commit to branch master
in repository node-after.

commit db3a3c13d983faeaecdb902173e79e9766c985a0
Author: Sruthi <srud at disroot.org>
Date:   Sat Dec 10 22:24:10 2016 +0530

    New upstream version 0.8.2
---
 .travis.yml  |   7 ++++
 README.md    | 114 ++++++++++++++++++++++++++++++++++++++++-------------------
 package.json |   3 +-
 3 files changed, 86 insertions(+), 38 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 84fd7ca..afd72d0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,3 +3,10 @@ node_js:
   - 0.6
   - 0.8
   - 0.9
+  - 0.10
+  - 0.12
+  - 4.2.4
+  - 5.4.1
+  - iojs-1
+  - iojs-2
+  - iojs-3
diff --git a/README.md b/README.md
index 0012d35..fc69096 100644
--- a/README.md
+++ b/README.md
@@ -6,38 +6,88 @@ Invoke callback after n calls
 
 ## Example
 
-    var after = require("after")
-        , next = after(3, logItWorks)
-
-    next()
-    next()
-    next() // it works
-
-    function logItWorks() {
-        console.log("it works!")
+```js
+var after = require("after")
+var db = require("./db") // some db.
+
+var updateUser = function (req, res) {
+  // use after to run two tasks in parallel,
+  // namely get request body and get session
+  // then run updateUser with the results
+  var next = after(2, updateUser)
+  var results = {}
+  
+  getJSONBody(req, res, function (err, body) {
+    if (err) return next(err)
+    
+    results.body = body
+    next(null, results)
+  })
+  
+  getSessionUser(req, res, function (err, user) {
+    if (err) return next(err)
+    
+    results.user = user
+    next(null, results)
+  })
+  
+  // now do the thing!
+  function updateUser(err, result) {
+    if (err) {
+      res.statusCode = 500
+      return res.end("Unexpected Error")
     }
-
-## Example with error handling
-
-    var after = require("after")
-        , next = after(3, logError)
-
-    next()
-    next(new Error("oops")) // logs oops
-    next() // does nothing
-
-    function logError(err) {
-        console.log(err)
+    
+    if (!result.user || result.user.role !== "admin") {
+      res.statusCode = 403
+      return res.end("Permission Denied")
     }
+    
+    db.put("users:" + req.params.userId, result.body, function (err) {
+      if (err) {
+        res.statusCode = 500
+        return res.end("Unexpected Error")
+      }
+      
+      res.statusCode = 200
+      res.end("Ok")  
+    })   
+  }
+}
+```
+
+## Naive Example
+
+```js
+var after = require("after")
+    , next = after(3, logItWorks)
+
+next()
+next()
+next() // it works
+
+function logItWorks() {
+    console.log("it works!")
+}
+```
 
-## After < 0.6.0
+## Example with error handling
 
-Older versions of after had iterators and flows in them.
+```js
+var after = require("after")
+    , next = after(3, logError)
 
-These have been replaced with seperate modules
+next()
+next(new Error("oops")) // logs oops
+next() // does nothing
 
- - [iterators][8]
- - [composite][9]
+// This callback is only called once.
+// If there is an error the callback gets called immediately
+// this avoids the situation where errors get lost.
+function logError(err) {
+    console.log(err)
+}
+```
 
 ## Installation
 
@@ -47,20 +97,10 @@ These have been replaced with seperate modules
 
 `npm test`
 
-## Blog post
-
- - [Flow control in node.js][3]
-
-## Examples :
-
- - [Determining the end of asynchronous operations][4]
- - [In javascript what are best practices for executing multiple asynchronous functions][5]
- - [JavaScript performance long running tasks][6]
- - [Synchronous database queries with node.js][7]
-
 ## Contributors
 
  - Raynos
+ - defunctzombie
 
 ## MIT Licenced
 
diff --git a/package.json b/package.json
index 2ee0785..b79796f 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "after",
   "description": "after - tiny flow control",
-  "version": "0.8.1",
+  "version": "0.8.2",
   "author": "Raynos <raynos2 at gmail.com>",
   "contributors": [
     {
@@ -23,5 +23,6 @@
     "control",
     "arch"
   ],
+  "license": "MIT",
   "repository": "git://github.com/Raynos/after.git"
 }

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



More information about the Pkg-javascript-commits mailing list