Skip to content

Commit e4b6ecb

Browse files
authored
Update Immediate.lua
1 parent 4e4b729 commit e4b6ecb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/ReplicatedStorage/Signal/Immediate.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,20 @@ local function RunHandlerInFreeThread(...)
8383
end
8484
end
8585

86-
function ScriptSignal.new()
86+
-- Creates a ScriptSignal object
87+
function ScriptSignal.new(): Class
8788
return setmetatable({
8889
_active = true,
8990
_head = nil
9091
}, ScriptSignal)
9192
end
9293

94+
-- Returns a boolean determining if the ScriptSignal object is usable
9395
function ScriptSignal:IsActive(): boolean
9496
return self._active == true
9597
end
9698

99+
-- Connects a function to the ScriptSignal object
97100
function ScriptSignal:Connect(
98101
handle: (...any) -> ()
99102
)
@@ -112,8 +115,8 @@ function ScriptSignal:Connect(
112115

113116
local node = {
114117
_signal = self,
115-
_handle = handle,
116118
_connection = nil,
119+
_handle = handle,
117120

118121
_next = _head,
119122
_prev = nil
@@ -135,6 +138,8 @@ function ScriptSignal:Connect(
135138
return connection
136139
end
137140

141+
-- Connects a function to a ScriptSignal object, but only allows that
142+
-- connection to run once; any later fires won't trigger anything
138143
function ScriptSignal:ConnectOnce(
139144
handle: (...any) -> ()
140145
)
@@ -156,6 +161,8 @@ function ScriptSignal:ConnectOnce(
156161
end)
157162
end
158163

164+
-- Yields the current thread until the signal is fired, returns what
165+
-- it was fired with
159166
function ScriptSignal:Wait(): (...any)
160167
local thread do
161168
thread = coroutine.running()
@@ -176,6 +183,7 @@ function ScriptSignal:Wait(): (...any)
176183
return coroutine.yield()
177184
end
178185

186+
-- Fires a ScriptSignal object with the arguments passed through it
179187
function ScriptSignal:Fire(...)
180188
local node = self._head
181189
while node ~= nil do
@@ -193,6 +201,8 @@ function ScriptSignal:Fire(...)
193201
end
194202
end
195203

204+
-- Disconnects all connections from a ScriptSignal object
205+
-- without destroying it and without making it unusable
196206
function ScriptSignal:DisconnectAll()
197207
local node = self._head
198208
while node ~= nil do
@@ -202,6 +212,8 @@ function ScriptSignal:DisconnectAll()
202212
end
203213
end
204214

215+
-- Destroys a ScriptSignal object, disconnecting all connections
216+
-- and making it unusable.
205217
function ScriptSignal:Destroy()
206218
if self._active == false then
207219
return
@@ -211,6 +223,8 @@ function ScriptSignal:Destroy()
211223
self._active = false
212224
end
213225

226+
-- Disconnects a connection, any :Fire calls from now on would not
227+
-- invoke this connection's function
214228
function ScriptConnection:Disconnect()
215229
if self.Connected == false then
216230
return
@@ -238,7 +252,7 @@ function ScriptConnection:Disconnect()
238252
self._node = nil
239253
end
240254

241-
export type ScriptSignal = typeof(
255+
export type Class = typeof(
242256
setmetatable({}, ScriptSignal)
243257
)
244258

0 commit comments

Comments
 (0)