[英]response.send understanding? (hubot-script)
我最近安装了hubot并正在对其进行测试。
现在我看到了……。 我不明白:
给定此代码( hubot-maps的一部分-maps.coffee 文件 )
robot.respond /(?:(satellite|terrain|hybrid)[- ])?map( me)? (.+)/i, (msg) ->
mapType = msg.match[1] or "roadmap"
location = encodeURIComponent(msg.match[3])
mapUrl = "http://maps.google.com/maps/api/staticmap?markers=" +
location +
"&size=400x400&maptype=" +
mapType +
"&sensor=false" +
"&format=png" # So campfire knows it's an image
url = "http://maps.google.com/maps?q=" +
location +
"&hl=en&sll=37.0625,-95.677068&sspn=73.579623,100.371094&vpsrc=0&hnear=" +
location +
"&t=m&z=11"
msg.send mapUrl
msg.send url
为什么我得到这样的回应
我在哪里得到第一个url
,然后是mapUrl
?
我希望先获取mapUrl
,然后获取url
从此hubot PR看来,Hubot msg.send
异步运行了msg.send
,因此没有保证的顺序。
副作用是,侦听器现在异步执行。 围绕message.done的行为应保持不变(直到message.done为true为止的过程)。
如果要在url
之前使用mapUrl
,则可以查看源代码中的send函数,该函数接受有序字符串列表。
// Public: Posts a message back to the chat source
//
// strings - One or more strings to be posted. The order of these strings
// should be kept intact.
//
// Returns nothing.
send (/* ...strings */) {
const strings = [].slice.call(arguments)
this.runWithMiddleware.apply(this, ['send', { plaintext: true }].concat(strings))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.