Bridge → Wait & Query

Wait & Query

Yield the current coroutine until a named event fires, a predicate is satisfied, or any one of a set of events fires first — and check event existence without yielding.

API

Bridge:Wait(event: string) → ...
Bridge:WaitUntil(event: string, predicate: (...any) → boolean) → ...
Bridge:WaitFirst(events: { string }) → event: string, ...
Bridge:Has(event: string) → boolean

Wait

Wait yields the calling coroutine until the named event fires once, then returns all arguments the event was fired with:

local player, killer = Bridge:Wait("playerDied")
print(player.Name, "was killed by", killer.Name)

WaitUntil

WaitUntil keeps yielding each time the event fires until the predicate returns a truthy value, then returns the arguments from that final fire:

-- Wait until a specific player dies
local player, killer = Bridge:WaitUntil("playerDied", function(p)
    return p.Name == "TargetPlayer"
end)
print("TargetPlayer died, killer:", killer.Name)

WaitFirst

WaitFirst yields until any one of the listed events fires, then returns the name of the event that fired along with its arguments:

-- Yield until any round-ending event
local event, data = Bridge:WaitFirst({ "roundWon", "roundDraw", "roundTimeout" })
print("Round ended via:", event)

Return values

FunctionReturns
Wait(event)All arguments the event was fired with.
WaitUntil(event, pred)All arguments from the fire that satisfied the predicate.
WaitFirst(events)The event name that fired first, followed by its arguments.

Has (non-yielding query)

Has returns immediately with a boolean — it does not yield. Use it to check whether any listeners are currently bound to an event name:

if Bridge:Has("playerDied") then
    Bridge.Emit("playerDied", { player = player, killer = killer })
end
Wait, WaitUntil, and WaitFirst all yield the calling coroutine. Call them inside a task.spawn or coroutine if you do not want to block the current thread.

See also

← Bridge  ·  On & Emit | register listeners and emit  ·  Broadcast | server-to-client events  ·  Listener | client-side event subscription