Skip to content

Commit

Permalink
modified pubsub:subscribe_once to return the wrapper function created…
Browse files Browse the repository at this point in the history
… so it's possible to unsub if needed
  • Loading branch information
1bardesign committed Aug 23, 2024
1 parent e10a6bf commit 9b8ecf0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pubsub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function pubsub:subscribe(event, callback)
end

--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)
local f
local called = false
Expand All @@ -107,6 +108,7 @@ function pubsub:subscribe_once(event, callback)
end
end
self:subscribe(event, f)
return f
end

--unsubscribe from an event
Expand Down

0 comments on commit 9b8ecf0

Please sign in to comment.