@@ -83,17 +83,20 @@ local function RunHandlerInFreeThread(...)
83
83
end
84
84
end
85
85
86
- function ScriptSignal .new ()
86
+ -- Creates a ScriptSignal object
87
+ function ScriptSignal .new (): Class
87
88
return setmetatable ({
88
89
_active = true ,
89
90
_head = nil
90
91
}, ScriptSignal )
91
92
end
92
93
94
+ -- Returns a boolean determining if the ScriptSignal object is usable
93
95
function ScriptSignal :IsActive (): boolean
94
96
return self ._active == true
95
97
end
96
98
99
+ -- Connects a function to the ScriptSignal object
97
100
function ScriptSignal :Connect (
98
101
handle : (...any ) -> ()
99
102
)
@@ -112,8 +115,8 @@ function ScriptSignal:Connect(
112
115
113
116
local node = {
114
117
_signal = self ,
115
- _handle = handle ,
116
118
_connection = nil ,
119
+ _handle = handle ,
117
120
118
121
_next = _head ,
119
122
_prev = nil
@@ -135,6 +138,8 @@ function ScriptSignal:Connect(
135
138
return connection
136
139
end
137
140
141
+ -- Connects a function to a ScriptSignal object, but only allows that
142
+ -- connection to run once; any later fires won't trigger anything
138
143
function ScriptSignal :ConnectOnce (
139
144
handle : (...any ) -> ()
140
145
)
@@ -156,6 +161,8 @@ function ScriptSignal:ConnectOnce(
156
161
end )
157
162
end
158
163
164
+ -- Yields the current thread until the signal is fired, returns what
165
+ -- it was fired with
159
166
function ScriptSignal :Wait (): (... any )
160
167
local thread do
161
168
thread = coroutine.running ()
@@ -176,6 +183,7 @@ function ScriptSignal:Wait(): (...any)
176
183
return coroutine.yield ()
177
184
end
178
185
186
+ -- Fires a ScriptSignal object with the arguments passed through it
179
187
function ScriptSignal :Fire (...)
180
188
local node = self ._head
181
189
while node ~= nil do
@@ -193,6 +201,8 @@ function ScriptSignal:Fire(...)
193
201
end
194
202
end
195
203
204
+ -- Disconnects all connections from a ScriptSignal object
205
+ -- without destroying it and without making it unusable
196
206
function ScriptSignal :DisconnectAll ()
197
207
local node = self ._head
198
208
while node ~= nil do
@@ -202,6 +212,8 @@ function ScriptSignal:DisconnectAll()
202
212
end
203
213
end
204
214
215
+ -- Destroys a ScriptSignal object, disconnecting all connections
216
+ -- and making it unusable.
205
217
function ScriptSignal :Destroy ()
206
218
if self ._active == false then
207
219
return
@@ -211,6 +223,8 @@ function ScriptSignal:Destroy()
211
223
self ._active = false
212
224
end
213
225
226
+ -- Disconnects a connection, any :Fire calls from now on would not
227
+ -- invoke this connection's function
214
228
function ScriptConnection :Disconnect ()
215
229
if self .Connected == false then
216
230
return
@@ -238,7 +252,7 @@ function ScriptConnection:Disconnect()
238
252
self ._node = nil
239
253
end
240
254
241
- export type ScriptSignal = typeof (
255
+ export type Class = typeof (
242
256
setmetatable ({}, ScriptSignal )
243
257
)
244
258
0 commit comments