context :
i need to call a function (function A) to make HTTP request two time, after this, i need to call another fonction (function B) that compute the two array
the normal order should be
- (Function A & Function A) asynchronously
- when the 2 other are done, Function B
so i turned myself to promise, but here is the issue, i can't figured out how to syntax it properly, i use Coffeescript.
here's what i got so far, but right now it's not working
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