Created
January 8, 2012 13:49
-
-
Save kaven276/1578412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5720c3794c7e34411c37276f9362165cb1add7b8 Mon Sep 17 00:00:00 2001 | |
From: Li Yong <[email protected]> | |
Date: Sun, 8 Jan 2012 20:44:36 +0800 | |
Subject: [PATCH] soap server can have async operation in fiber. | |
A soap server function often have to call other network service for example db server to help process the soap request, but in node's "soap", it call the server function and get the return value in sync way, it will not to wait the async process to finish, using node's fibers module, we can let soap(server.js) to wait the server function to finish it's async operation, and then got the return value. | |
Note that fibers will not block, so it's safe. But fibers say he will support linux/unix/osx, but not windows (maybe the c++ lib has only none windows version). So if you want the updated soap version on windows, it does't works. | |
--- | |
lib/server.js | 3 +++ | |
package.json | 1 + | |
2 files changed, 4 insertions(+), 0 deletions(-) | |
diff --git a/lib/server.js b/lib/server.js | |
index 96fc0f2..d2163ee 100644 | |
--- a/lib/server.js | |
+++ b/lib/server.js | |
@@ -3,6 +3,7 @@ | |
* MIT Licensed | |
*/ | |
+require('fibers'); | |
var url = require('url'), | |
compress = null; | |
@@ -59,6 +60,7 @@ Server.prototype._requestListener = function(req, res) { | |
gunzip.end(); | |
gunzip = null | |
} | |
+ Fiber(function() { | |
try { | |
result = self._process(xml, req.url); | |
} | |
@@ -67,6 +69,7 @@ Server.prototype._requestListener = function(req, res) { | |
} | |
res.write(result); | |
res.end(); | |
+ }).run(); | |
}); | |
} | |
else { | |
diff --git a/package.json b/package.json | |
index 715e787..8efa698 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -7,6 +7,7 @@ | |
"dependencies": { | |
"node-expat": ">= 1.3.0", | |
"request": "=2.2.6" | |
+ ,"fibers": "0.6.4" | |
}, | |
"repository" : { | |
"type":"git", | |
-- | |
1.7.7.3+GitX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment