Skip to content

Instantly share code, notes, and snippets.

@howmanysmall
Last active August 4, 2021 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howmanysmall/105d5f0630bf62cc07640c6ee7a563de to your computer and use it in GitHub Desktop.
Save howmanysmall/105d5f0630bf62cc07640c6ee7a563de to your computer and use it in GitHub Desktop.
for a quick fix
local EnumList = require(script.Parent.EnumList)
local Timer = require(script.Parent.Timer)
local Thread = {}
Thread.DelayRepeatBehavior = EnumList.new("DelayRepeatBehavior", {"Delayed", "Immediate"})
function Thread.SpawnNow(func, ...)
local args = table.pack(...)
task.spawn(function()
func(table.unpack(args, 1, args.n))
end)
local conn = {}
conn.Connected = true
conn.connected = true
function conn:Disconnect()
if self.Connected then
self.Connected = false
self.connected = false
end
end
conn.disconnect = conn.Disconnect
return conn
end
function Thread.Spawn(func, ...)
local args = table.pack(...)
local stop = false
task.defer(function()
if stop then
return
end
func(table.unpack(args, 1, args.n))
end)
local conn = {}
conn.Connected = true
conn.connected = true
function conn:Disconnect()
if self.Connected then
self.Connected = false
self.connected = false
stop = true
end
end
conn.disconnect = conn.Disconnect
return conn
end
function Thread.Delay(waitTime, func, ...)
local args = table.pack(...)
local stop = false
task.delay(waitTime, function()
if stop then
return
end
func(table.unpack(args, 1, args.n))
end)
local conn = {}
conn.Connected = true
conn.connected = true
function conn:Disconnect()
if self.Connected then
self.Connected = false
self.connected = false
stop = true
end
end
conn.disconnect = conn.Disconnect
return conn
end
function Thread.DelayRepeat(intervalTime, func, behavior, ...)
local args = table.pack(...)
if behavior == nil then
behavior = Thread.DelayRepeatBehavior.Delayed
end
assert(Thread.DelayRepeatBehavior:Is(behavior), "Invalid behavior")
local timer = Timer.new(intervalTime)
timer.Tick:Connect(function()
func(table.unpack(args, 1, args.n))
end)
if behavior == Thread.DelayRepeatBehavior.Immediate then
timer:StartNow()
else
timer:Start()
end
local conn = {}
conn.Connected = true
conn.connected = true
function conn:Disconnect()
if self.Connected then
self.Connected = false
self.connected = false
timer:Destroy()
end
end
conn.disconnect = conn.Disconnect
return conn
end
return Thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment