上下文2个异步函数:承诺与CoffeeScript的
我需要调用一个函数(函数A)来进行HTTP请求两个时间,在此之后,我需要调用另一个fonction(函数B),其计算两个阵列
正常顺序应该是
- (功能A &函数A)异步
- 当2-其它完成后,功能B
所以我让自己承诺,但这里是问题,我想不出如何正确的语法,我使用Coffeescript。
这是我走到这一步,但现在它不工作
myCoolPromise =() ->
return new Promise (resolve, reject) ->
postRequest(diagUrl, diagnosisBody, storesConnectionObject)
postRequest(storesUrl, brandBody, storesObject)
success = true
if success
resolve 'stuff worked'
else
reject Error 'it broke'
myCoolPromise(storesObject.storesArray, storesConnectionObject.storesArray, absentObject).then (response) ->
console.log 'success', response
handleResult(storesObject.storesArray, storesConnectionObject.storesArray, absentObject)
.catch (error) ->
console.error 'failed', error
我不明白'myCoolPromise'应该做什么。它似乎不是异步的,“成功”永远是真的,所以你不应该在这里使用promise? – Bergi