response.send 了解吗? (集线器脚本)

response.send understanding? (hubot-script)

我最近安装了 hubot 并正在测试它。

现在我看到了……我不明白:

鉴于此代码(hubot-maps - maps.coffee file 的一部分)

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

this hubot PR 开始,Hubot 似乎异步运行您的 msg.send,因此无法保证顺序。

As a side effect, listeners are now executed asynchronously. Behavior around message.done should remain the same (process until message.done is true).

如果你想在 url 之前 mapUrl,你可以看看 source code 中的发送函数,它接受一个有序字符串列表。

// 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))
}