简体   繁体   English

回应。发送理解? (脚本)

[英]response.send understanding? (hubot-script)

I recently installed hubot and was testing it. 我最近安装了hubot并正在对其进行测试。

Now I saw sth. 现在我看到了……。 I don't understand: 我不明白:

Given this code (part of hubot-maps - maps.coffee file ) 给定此代码( 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

Why I do get a response like this 为什么我得到这样的回应

在此处输入图片说明

where I get first url and then mapUrl ? 我在哪里得到第一个url ,然后是mapUrl

I expect to get mapUrl first and then url 我希望先获取mapUrl ,然后获取url

From this hubot PR , it looks like Hubot runs your msg.send s asynchronously, so there is no guaranteed order. 从此hubot PR看来,Hubot msg.send异步运行了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). 围绕message.done的行为应保持不变(直到message.done为true为止的过程)。

If you want mapUrl before url , you can take a look at the send function in the source code , which accepts a list of ordered strings. 如果要在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.

相关问题 NodeJS-response.send()不是函数 - NodeJS - response.send() is not a function 节点js中response.send和response.write之间的区别 - Difference between response.send and response.write in node js Express response.send() JavaScript fetch() 未收到 object ... 为什么? - Express response.send() object not received by JavaScript fetch() … why? express.js - 如何拦截 response.send() / response.json() - express.js - how to intercept response.send() / response.json() 如何使用“response.send()”创建一个加载animation,然后在解决后将其更改为promise的结果? - How to create a loading animation using “response.send()”, then change it to the result of a promise after it is resolved? 编写 Google Cloud Functions 时,我应该在“finally”块中使用 response.send() 吗? - Should I use response.send() in 'finally' block when writing Google Cloud Functions? 如何在 express.js 中设置使用 response.send () 发送的数据的样式 - How can I style the data sent using response.send () in express.js 如何在hubot中编写脚本? - How to script in hubot? response.send(来自node.js / restify应用程序)默认将整数序列化为32位低/高部分吗? - response.send (from node.js / restify app) by default serializes integer into 32-bit low/high parts? Hubot响应回调调用了两次 - hubot response callback called twice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM