You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jh...@apache.org on 2013/01/30 13:31:48 UTC

[1/2] git commit: Switch to async readline()

Switch to async readline()


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/a614678c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a614678c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a614678c

Branch: refs/heads/nodejs_couchdb
Commit: a614678c484f2f88a7baf729133a5bbae34e27b8
Parents: 4a18ddf
Author: Jason Smith (work) <jh...@iriscouch.com>
Authored: Tue Jan 29 12:20:58 2013 +0000
Committer: Jason Smith (work) <jh...@iriscouch.com>
Committed: Tue Jan 29 12:20:58 2013 +0000

----------------------------------------------------------------------
 share/server/loop.js |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a614678c/share/server/loop.js
----------------------------------------------------------------------
diff --git a/share/server/loop.js b/share/server/loop.js
index fcd016f..76cbbff 100644
--- a/share/server/loop.js
+++ b/share/server/loop.js
@@ -146,7 +146,18 @@ var Loop = function() {
       respond(["error","unnamed_error",e.toSource()]);
     }
   };
-  while (line = readline()) {
+
+  if(readline.async) {
+    readline.async(got_line)
+  } else {
+    while(line = readline())
+      got_line(null, line)
+  }
+
+  function got_line(er, line) {
+    if(er)
+      throw er
+
     cmd = JSON.parse(line);
     State.line_length = line.length;
     try {
@@ -161,6 +172,9 @@ var Loop = function() {
     } catch(e) {
       handleError(e);
     }
+
+    if(readline.async)
+      readline.async(got_line)
   };
 };