-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
83 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = function(batches, context, next) { | ||
console.log("before invoke:", batches); | ||
var result = next(batches, context); | ||
console.log("after invoke:", batches, result); | ||
result.then(function(result) { | ||
console.log("after invoke:", batches, result); | ||
}); | ||
return result; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = function(name, args, context, next) { | ||
console.log("before invoke:", name, args); | ||
var result = next(name, args, context); | ||
console.log("after invoke:", name, args, result); | ||
result.then(function(result) { | ||
console.log("after invoke:", name, args, result); | ||
}); | ||
return result; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = function(name, args, context, next) { | ||
console.log("before invoke:", name, args); | ||
var result = next(name, args, context); | ||
console.log("after invoke:", name, args, result); | ||
result.then(function(result) { | ||
console.log("after invoke:", name, args, result); | ||
}); | ||
return result; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
module.exports = function(message) { | ||
return function(request, context, next) { | ||
var start = Date.now(); | ||
function showstat() { | ||
var response = next(request, context); | ||
response.then(function() { | ||
var end = Date.now(); | ||
console.log(message + ': It takes ' + (end - start) + ' ms.'); | ||
} | ||
var response = next(request, context); | ||
if (hprose.Future.isPromise(response)) { | ||
response.then(showstat); | ||
} | ||
else { | ||
showstat(); | ||
} | ||
}); | ||
return response; | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = function(name, args, context, next) { | ||
console.log("before invoke:", name, args); | ||
var result = next(name, args, context); | ||
console.log("after invoke:", name, args, result); | ||
result.then(function(result) { | ||
console.log("after invoke:", name, args, result); | ||
}); | ||
return result; | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* * | ||
* HproseClient for Node.js. * | ||
* * | ||
* LastModified: Apr 1, 2016 * | ||
* LastModified: Jul 4, 2016 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -1015,14 +1015,9 @@ function Client(uri, functions, settings) { | |
_invokeHandler = _invokeHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(name, args, context) { | ||
try { | ||
var result = handler(name, args, context, next); | ||
if (Future.isFuture(result)) { return result; } | ||
return Future.value(result); | ||
} | ||
catch (e) { | ||
return Future.error(e); | ||
} | ||
return Future.sync(function() { | ||
return handler(name, args, context, next); | ||
}); | ||
}; | ||
}, invokeHandler); | ||
} | ||
|
@@ -1031,14 +1026,9 @@ function Client(uri, functions, settings) { | |
_batchInvokeHandler = _batchInvokeHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(batches, context) { | ||
try { | ||
var result = handler(batches, context, next); | ||
if (Future.isFuture(result)) { return result; } | ||
return Future.value(result); | ||
} | ||
catch (e) { | ||
return Future.error(e); | ||
} | ||
return Future.sync(function() { | ||
return handler(batches, context, next); | ||
}); | ||
}; | ||
}, batchInvokeHandler); | ||
} | ||
|
@@ -1047,14 +1037,9 @@ function Client(uri, functions, settings) { | |
_beforeFilterHandler = _beforeFilterHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(request, context) { | ||
try { | ||
var response = handler(request, context, next); | ||
if (Future.isFuture(response)) { return response; } | ||
return Future.value(response); | ||
} | ||
catch (e) { | ||
return Future.error(e); | ||
} | ||
return Future.sync(function() { | ||
return handler(request, context, next); | ||
}); | ||
}; | ||
}, beforeFilterHandler); | ||
} | ||
|
@@ -1063,14 +1048,9 @@ function Client(uri, functions, settings) { | |
_afterFilterHandler = _afterFilterHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(request, context) { | ||
try { | ||
var response = handler(request, context, next); | ||
if (Future.isFuture(response)) { return response; } | ||
return Future.value(response); | ||
} | ||
catch (e) { | ||
return Future.error(e); | ||
} | ||
return Future.sync(function() { | ||
return handler(request, context, next); | ||
}); | ||
}; | ||
}, afterFilterHandler); | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* * | ||
* Hprose Service for Node.js. * | ||
* * | ||
* LastModified: Jun 6, 2016 * | ||
* LastModified: Jul 4, 2016 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -188,13 +188,9 @@ function Service() { | |
}); | ||
} | ||
} | ||
var result = invoke(name, args, context); | ||
if (Future.isPromise(result)) { | ||
return result.then(null, function(e) { | ||
return sendError(e, context); | ||
}); | ||
} | ||
return result; | ||
return invoke(name, args, context).then(null, function(e) { | ||
return sendError(e, context); | ||
}); | ||
} | ||
catch (e) { | ||
return sendError(e, context); | ||
|
@@ -225,19 +221,15 @@ function Service() { | |
} | ||
else { | ||
if (passContext) { args.push(context); } | ||
return callService(args, context); | ||
return Future.toPromise(callService(args, context)); | ||
} | ||
} | ||
|
||
function invoke(name, args, context) { | ||
var result = _invokeHandler(name, args, context); | ||
if (Future.isPromise(result)) { | ||
return result.then(function(result) { | ||
if (isError(result)) { throw result; } | ||
return afterInvoke(name, args, context, result); | ||
}); | ||
} | ||
return afterInvoke(name, args, context, result); | ||
return _invokeHandler(name, args, context).then(function(result) { | ||
if (isError(result)) { throw result; } | ||
return afterInvoke(name, args, context, result); | ||
}); | ||
} | ||
|
||
function afterInvoke(name, args, context, result) { | ||
|
@@ -347,34 +339,43 @@ function Service() { | |
return stream.bytes; | ||
} | ||
|
||
function delayError(e, context) { | ||
var err = endError(e, context); | ||
if (_errorDelay > 0) { | ||
return Future.delayed(_errorDelay, err); | ||
} | ||
else { | ||
return Promise.value(err); | ||
} | ||
} | ||
|
||
function beforeFilterHandler(request, context) { | ||
var response; | ||
try { | ||
request = inputFilter(request, context); | ||
response = _afterFilterHandler(request, context); | ||
} | ||
catch (e) { | ||
response = endError(e, context); | ||
if (_errorDelay > 0) { | ||
response = Future.delayed(_errorDelay, response); | ||
} | ||
} | ||
if (Future.isPromise(response)) { | ||
return response.then(function(response) { | ||
return outputFilter(response, context); | ||
response = _afterFilterHandler(request, context).then(null, function(e) { | ||
return delayError(e, context); | ||
}); | ||
} | ||
else { | ||
return outputFilter(response, context); | ||
catch (e) { | ||
response = delayError(e, context); | ||
} | ||
return response.then(function(value) { | ||
return outputFilter(value, context); | ||
}); | ||
} | ||
|
||
function afterFilterHandler(request, context) { | ||
var input = new BytesIO(request); | ||
switch (input.readByte()) { | ||
case Tags.TagCall: return doInvoke(input, context); | ||
case Tags.TagEnd: return doFunctionList(context); | ||
default: throw new Error('Wrong Request: \r\n' + BytesIO.toString(request)); | ||
try { | ||
var input = new BytesIO(request); | ||
switch (input.readByte()) { | ||
case Tags.TagCall: return doInvoke(input, context); | ||
case Tags.TagEnd: return Future.value(doFunctionList(context)); | ||
default: throw new Error('Wrong Request: \r\n' + BytesIO.toString(request)); | ||
} | ||
} | ||
catch (e) { | ||
return Future.error(e); | ||
} | ||
} | ||
|
||
|
@@ -1067,7 +1068,9 @@ function Service() { | |
_beforeFilterHandler = _beforeFilterHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(request, context) { | ||
return handler(request, context, next); | ||
return Future.sync(function() { | ||
return handler(request, context, next); | ||
}); | ||
}; | ||
}, beforeFilterHandler); | ||
} | ||
|
@@ -1076,7 +1079,9 @@ function Service() { | |
_afterFilterHandler = _afterFilterHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(request, context) { | ||
return handler(request, context, next); | ||
return Future.sync(function() { | ||
return handler(request, context, next); | ||
}); | ||
}; | ||
}, afterFilterHandler); | ||
} | ||
|
@@ -1085,7 +1090,9 @@ function Service() { | |
_invokeHandler = _invokeHandlers.reduceRight( | ||
function(next, handler) { | ||
return function(name, args, context) { | ||
return handler(name, args, context, next); | ||
return Future.sync(function() { | ||
return handler(name, args, context, next); | ||
}); | ||
}; | ||
}, invokeHandler); | ||
} | ||
|
This file contains 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