diff --git a/README.md b/README.md index fceecae..7410813 100644 --- a/README.md +++ b/README.md @@ -553,3 +553,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/node-webot/webot/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + diff --git a/lib/rule.js b/lib/rule.js index 2eb6d47..0526bb7 100644 --- a/lib/rule.js +++ b/lib/rule.js @@ -238,6 +238,18 @@ Rule.prototype.exec = function(info, cb) { return cb(); } + if (rule.replies) { + verbose('adding wait rule for replies of ' + rule.name); + var oldcb = cb; + cb = function (err, next) { + // 在handler中设置info.skipReplies=true来跳过wait rule + if (!info.skipReplies) { + info.wait('_reply_' + rule.name); + } + oldcb(err, next); + } + } + // 为数组时会随机挑一个 if (Array.isArray(fn) && fn.length >= 1) { verbose('handler is an array, pick one'); diff --git a/lib/webot.js b/lib/webot.js index 93df666..099c128 100644 --- a/lib/webot.js +++ b/lib/webot.js @@ -426,10 +426,6 @@ Webot.prototype._reply = function(ruleList, info, cb) { return end(err, result); } if (result || info.ended) { - // 存在要求回复的规则 - if (rule.replies) { - info.wait('_reply_' + rule.name); - } if (!result) { error('request ended with no good reply.'); }