Promise works incorrectly

i tried to make thread with using module “promise”, but it said the errors.

function Move()
    print("using!")
    task.wait(3)
    print("used!")
end
local MovePromise
MovePromise = Promise.new(function(resolve, reject, onCancel)
    local Succ, Err = xpcall(Move, debug.traceback)
    if not Succ then
        reject(Err)
    end
    resolve()
end):catch(warn)
task.wait(1)
MovePromise:Cancel()

It says that:

From the stack trace I see you are using Sleitnick’s Signal. With the given code and without more context, I cannot seem to reproduce the error.

However, there are two things to be changed in the snippet. Promise:cancel() is only supported in lower case, and promises already safely catch errors. For uncontrolled rejections, the traceback is passed into the rejection handler automatically.


(Source: Promise | roblox-lua-promise)

local function move()
	print("moving")
	task.wait(3)
	--error("hehehe")
	print("moved")
end

local movePromise = Promise.new(function(resolve, reject, onCancel)
	onCancel(function()
		print("Cancelled")
	end)
	
	move()
	resolve()
end):andThen(function()
	print("Finished")
end):catch(warn)

task.wait(1)
movePromise:cancel()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.