--!strict

local CancellableDelay = {}
CancellableDelay.__index = CancellableDelay

setmetatable(CancellableDelay, {
	__call = function (self, ...)
		return self.new(...)
	end
})

function CancellableDelay.new(delayTime:number, callback:(any:any) -> any, ...:any?)
	local self = setmetatable({}, CancellableDelay)
	self.__callback = callback
	self.__cancelled = false
	self.__args = ...
	self.Finished = false
	self.Result = nil
	task.delay(delayTime, function()
		if not self.__cancelled then
			self.Result = self.__callback(self.__args)
		end
		self.Finished = true
	end)
	return self
end

function CancellableDelay:Cancel()
	self.__cancelled = true
	self.Finished = true
end

return CancellableDelay
