Hello,
I’m currently learning about promise and trying them out. I tried different codes and I think I’m getting used to it. But I don’t understand why in this code, even if the promise is cancelled because it’ll not print “Promise done”, it won’t print “Cancel”. Unless I change promise.new to promise.async on line HERE. Anyone knows why ?
local Promise = require(game.Promise)
function a()
return Promise.async(function(resolve)
print("promise start")
resolve()
end):andThen(function()
return Promise.new(function(resolve, reject, onCancel) --< HERE
if onCancel(function()
print("Cancel")
end) then return end
print("waiting")
wait(7)
print("waiting ended")
resolve()
end)
end):andThen(function()
print("promise done")
end)
end
local promise = a()
wait(5)
print("cancel the promise !")
promise:cancel()