-2
我未能在for循環中使用承諾。我需要先後得到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
[閉合的可能的複製範圍未被捕獲? - Coffeescript](http://stackoverflow.com/questions/11996218/closure-scope-not-captured-coffeescript) –