Skip to content

Commit

Permalink
Fix the node request object to have an on() method and always process…
Browse files Browse the repository at this point in the history
… callbacks asynchronously
  • Loading branch information
kriszyp committed Aug 22, 2012
1 parent cdf59a1 commit 3455ff8
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions jsgi/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ exports.Node = function(nodeApp){
var endListeners = [];
var bodyDeferred;
var responseDeferred = defer();
nodeApp({
var nodeRequest = {
headers: request.headers,
httpVersionMajor: request.version[0],
httpVersionMinor: request.version[1],
addListener: function(event, callback){
if(event == "data"){
when(request.body && request.body.forEach(function(data){
callback(data);
}), function(){
endListeners.forEach(function(listener){
listener();
process.nextTick(function(){
if(event == "data"){
when(request.body && request.body.forEach(function(data){
callback(data);
}), function(){
endListeners.forEach(function(listener){
listener();
});
endListeners = null;
});
endListeners = null;
});
}
if(event == "end"){
if(endListeners){
endListeners.push(callback);
}else{
callback();
}
}
if(event == "end"){
if(endListeners){
endListeners.push(callback);
}else{
callback();
}
}
});
return this;
},
pause: function(){
Expand All @@ -36,7 +38,9 @@ exports.Node = function(nodeApp){
resume: function(){

}
},
}
nodeRequest.on = nodeRequest.addListener;
nodeApp(nodeRequest,
{
writeHead: function(status, headers){
var write;
Expand Down

0 comments on commit 3455ff8

Please sign in to comment.