Skip to content
FutureBlitz

    Install

    Import std.events.event

    Event

    std.events.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)

    std/events/event.fb, line 119

    • Public New() constructor #

      A new Event, with no handlers.

    • Public Property Count: Int property #

      How many handlers it has: those not cancelled, whose owners, if they have them, are there.

    • Public Method Subscribe(handler: Func(T)): Subscription method #

      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.

    • Public Method Subscribe<O: Class>(owner: O, handler: Func(O, T)): Subscription method #

      Adds handler for owner, which it's called with, after the handlers added before it, until the Subscription it gives is cancelled or the owner goes, as the handler holds it weakly. The handler gets the owner, so it needn't capture it, which would keep it: a handler that captures its owner keeps it as long as the Event keeps the handler. The next Emit or Clear after the owner goes takes the handler out, as a Subscribe does now and then.

    • Public Method Emit(value: T) method #

      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.

    • Public Method Clear() method #

      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.