mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
modified pubsub:subscribe_once to return the wrapper function created so it's possible to unsub if needed
This commit is contained in:
parent
e10a6bf498
commit
9b8ecf0e0d
@ -96,6 +96,7 @@ function pubsub:subscribe(event, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--subscribe to an event, automatically unsubscribe once called
|
--subscribe to an event, automatically unsubscribe once called
|
||||||
|
--return the function that can be used to unsubscribe early if needed
|
||||||
function pubsub:subscribe_once(event, callback)
|
function pubsub:subscribe_once(event, callback)
|
||||||
local f
|
local f
|
||||||
local called = false
|
local called = false
|
||||||
@ -107,6 +108,7 @@ function pubsub:subscribe_once(event, callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:subscribe(event, f)
|
self:subscribe(event, f)
|
||||||
|
return f
|
||||||
end
|
end
|
||||||
|
|
||||||
--unsubscribe from an event
|
--unsubscribe from an event
|
||||||
|
Loading…
Reference in New Issue
Block a user