【发布时间】:2017-03-30 02:13:09
【问题描述】:
我没有在 for 循环中使用 Promise。我需要连续完成 reqWithPromise 方法
getUserInfoById: () ->
ids = [196658162, 244668541, 84634196, 1234567, 45367181]
last = Promise.resolve()
for id of ids
id = ids[id]
url = "https://api.vk.com/method/users.get?fields=photo,status&user_ids=#{id}&access_token=#{atom.config.get('vk-messenger.apiToken')}&v=5.60"
last = last.then(() -> reqWithPromise(url));
reqWithPromise = (url) ->
https.get url, (@response) ->
@response.on 'data', (chunk) ->
@userModel = JSON.parse(chunk)['response'][0]
console.log @userModel.id + ' ' + @userModel.first_name
我明白了
5 times: 45367181 Daniil
【问题讨论】:
标签: javascript api asynchronous coffeescript promise