evaera / roblox-lua-promise

Promise implementation for Roblox
https://eryn.io/roblox-lua-promise/
MIT License
275 stars 74 forks source link

Queued callbacks from a cancelled sub-promise should not be run #67

Closed evaera closed 2 years ago

evaera commented 3 years ago
local h = Promise.new(function(resolve)
    wait(3)

    resolve()
end)

local andthen1 = h:andThen(function()
    print("this should NOT print, but it does today")
end)

local andthen2 = h:andThen(function()
    print("this should print")
end)

andthen1:cancel()

x = Promise.new(executor), with executor function executor, and then chain onto it with andThen.

In effect, calling x:andThen(cb) is registering a callback (cb) to be run when x resolves. it returns a new promise, y, whose executor you do not control; it's controlled by the promise library, and it is what calls cb internally.

This is different, because the code inside cb is not related to promise y in the same way that the code in executor is related to promise x

I think this is confusing behavior, so we can just change it in a new version