feat(bait): add catchOnce function

dev
TorchedSammy 2021-12-04 17:59:19 -04:00
parent dd45766bae
commit 51b1219003
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 7 additions and 0 deletions

View File

@ -38,6 +38,7 @@ failed, etc. To find all available hooks, see doc hooks.`)
L.SetField(mod, "throw", luar.New(L, b.bthrow))
L.SetField(mod, "catch", luar.New(L, b.bcatch))
L.SetField(mod, "catchOnce", luar.New(L, b.bcatchOnce))
L.Push(mod)
@ -55,3 +56,9 @@ func (b *Bait) bthrow(name string, args ...interface{}) {
func (b *Bait) bcatch(name string, catcher func(...interface{})) {
b.Em.On(name, catcher)
}
// catchOnce(name, cb)
// Same as catch, but only runs the `cb` once and then removes the hook
func (b *Bait) bcatchOnce(name string, catcher func(...interface{})) {
b.Em.Once(name, catcher)
}