Skip to content

Commit

Permalink
Issue Sleitnick#56
Browse files Browse the repository at this point in the history
- Added Timer.Started and Timer.Stopped events
  • Loading branch information
noahrepublic committed Jul 15, 2022
1 parent e164f00 commit 3bd515c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/timer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function Timer.new(interval: number)
self.TimeFunction = time
self.AllowDrift = true
self.Tick = Signal.new()
self.Started = Signal.new()
self.Stopped = Signal.new()
return self
end

Expand Down Expand Up @@ -173,6 +175,7 @@ function Timer:Start()
else
self:_startTimerNoDrift()
end
self.Started:Fire()
end

--[=[
Expand Down Expand Up @@ -204,6 +207,7 @@ function Timer:Stop()
end
self._runHandle:Disconnect()
self._runHandle = nil
self.Stopped:Fire()
end

--[=[
Expand All @@ -227,4 +231,18 @@ function Timer:Destroy()
self:Stop()
end

function Timer:OnStart(callback)
if self.Started.Connected then
self.Started:Disconnect()
end
self.Started:Connect(callback)
end

function Timer:OnStop(callback)
if self.Stopped.Connected then
self.Stopped:Disconnect()
end
self.Stopped:Connect(callback)
end

return Timer

0 comments on commit 3bd515c

Please sign in to comment.