Import std.events.event
Event
class
Public Class Event<T>
The handlers that an Emit calls with its value, in the order they were added.
Examples
Local clicked = Event<Int>()
Local seen: Int[] = []
Local onClick = Function(x: Int)
seen.Add(x)
End Function
Local subscription = clicked.Subscribe(onClick)
clicked.Emit(1)
subscription.Cancel()
clicked.Emit(2)
Expect(seen == [1])
Expect(clicked.Count == 0 && !subscription.IsActive)-
A new Event, with no handlers.
-
How many handlers it has: those not cancelled, whose owners, if they have them, are there.
-
Adds
handler, which each Emit after this calls, after the handlers added before it, until the Subscription it gives is cancelled. An Emit that's calling handlers meanwhile doesn't. -
Adds
handlerforowner, which it's called with, after the handlers added before it, until the Subscription it gives is cancelled or theownergoes, as thehandlerholds it weakly. Thehandlergets theowner, so it needn't capture it, which would keep it: a handler that captures its owner keeps it as long as the Event keeps thehandler. The next Emit or Clear after theownergoes takes thehandlerout, as a Subscribe does now and then. -
Calls each handler with
value, in the order they were added. A handler added meanwhile waits for the next Emit, and one cancelled meanwhile, by a handler before it, isn't called. -
Takes every handler off, as their Subscriptions' Cancel would, and out at once at the end, as an Emit does.
Report an issue with this page or with FutureBlitz on GitHub.