Hi all!
Lately I’m learning ReScript, but there’s something really unclear to me about promises. Given the following snippet
const doSomethingElse = (val) => new Promise((resolve) => resolve(val))
const doSomething = () => new Promise((resolve) => resolve("done"))
const taskList = doSomething().then(res => {
console.log(`First task ${res}`);
return doSomethingElse(res);
})
const main = (async () => {
const result = await taskList
console.log(`All tasks: ${result}`)
})();
I tried to write the equivalent in ReScript, as it follows
let doSomethingElse = (res) => Js.Promise2.make(((~resolve, ~reject as _) => resolve(. res)))
let doSomething = () => Js.Promise2.make(((~resolve, ~reject as _) => resolve(. "done")))
let taskList = doSomething()
->Js.Promise2.then(async res => {
Js.log(`First task: ${res}`)
let result = await doSomethingElse(res)
result
});
let main = (async () => {
let result = await taskList
Js.log(`All tasks: ${result}`)
})();
but the results I’m getting are different, since in the ReScript version I’m getting All tasks: undefined
as output, but I don’t really understand why.
Thanks for any help,
Best!