@@ -103,13 +103,44 @@ end
103
103
local ErrorsOnAlreadyConnected = false
104
104
local IsToStringEnabled = true
105
105
106
+ export type Connection = {
107
+ -- [string]: any,
108
+
109
+ Connected : boolean ,
110
+ Disconnect : (self : Connection ) -> ()
111
+ }
112
+
113
+ export type Event = {
114
+ -- [string]: any,
115
+
116
+ IsActive : (self : Event ) -> boolean ,
117
+
118
+ Fire : (self : Event , ... any ) -> (),
119
+
120
+ Connect : (
121
+ self : Event , (... any ) -> ()
122
+ ) -> Connection ,
123
+
124
+ ConnectParallel : (
125
+ self : Event , (... any ) -> ()
126
+ ) -> Connection ,
127
+
128
+ Wait : (self : Event ) -> (... any ),
129
+
130
+ DisconnectAll : (self : Event ) -> (),
131
+ Destroy : (self : Event ) -> (),
132
+
133
+ GetName : (self : Event ) -> string ,
134
+ SetName : (self : Event , string ) -> ()
135
+ }
136
+
106
137
local Signal = {}
107
138
Signal .__index = Signal
108
139
109
140
local Connection = {}
110
141
Connection .__index = Connection
111
142
112
- function Signal .new (name )
143
+ function Signal .new (name : string ? ): Event
113
144
local self = setmetatable ({
114
145
_name = typeof (name ) == " string" and name or " " ,
115
146
_active = true ,
@@ -150,7 +181,7 @@ local function Connect(self, func, is_wait)
150
181
return connection
151
182
end
152
183
153
- function Signal :Connect (func )
184
+ function Signal :Connect (func ): Connection
154
185
assert (
155
186
typeof (func ) == " function" ,
156
187
" :Connect must be called with a function -" .. self ._name
@@ -159,7 +190,7 @@ function Signal:Connect(func)
159
190
return Connect (self , func )
160
191
end
161
192
162
- function Signal :ConnectParallel (func )
193
+ function Signal :ConnectParallel (func ): Connection
163
194
assert (
164
195
typeof (func ) == " function" ,
165
196
" :ConnectParallel must be called with a function -" .. self ._name
@@ -202,7 +233,7 @@ function Connection:Disconnect()
202
233
self ._prev = nil
203
234
end
204
235
205
- function Signal :Wait ()
236
+ function Signal :Wait (): ( ... any )
206
237
Connect (self , coroutine.running (), true )
207
238
208
239
return coroutine.yield ()
@@ -255,7 +286,7 @@ function Signal:GetName()
255
286
return self ._name
256
287
end
257
288
258
- function Signal :SetName (name )
289
+ function Signal :SetName (name : string )
259
290
assert (typeof (name ) == " string" , " Name must be a string!" )
260
291
261
292
self ._name = name
@@ -269,7 +300,7 @@ if IsToStringEnabled == false then
269
300
Signal .__tostring = nil
270
301
end
271
302
272
- function Signal :__call (_ , func )
303
+ function Signal :__call (_ , func ): Connection
273
304
assert (
274
305
typeof (func ) == " function" ,
275
306
" :Connect must be called with a function -" .. self ._name
0 commit comments