-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathSignalling.lua
42 lines (31 loc) · 941 Bytes
/
Signalling.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local Signalling = {} --// Is that right?
function Signalling:Fire(...)
self.Fired = true
for i, v in next, self.Callbacks do
if type(v) == "function" then
task.spawn(v, ...)
elseif type(v) == "thread" then
task.spawn(coroutine.resume, v, ...)
table.remove(self.Callbacks, table.find(self.Callbacks, v))
end
end
return Signalling
end
function Signalling:Wait(Arg, C)
if Arg == "f" and self.Fired then
return;
end
table.insert(self.Callbacks, coroutine.running())
return coroutine.yield()
end
function Signalling:Connect(Callback)
table.insert(self.Callbacks, Callback)
return self
end
function Signalling:Disconnect(Callback)
table.remove(self.Callbacks, table.find(self.Callbacks, Callback))
end
function Signalling.new()
return setmetatable({ Callbacks = {} }, { __index = Signalling })
end
return Signalling