Skip to content
FutureBlitz

    Install

    Import std.events.event

    std.events.event

    Event<T>: the handlers that an Emit calls, in the order they were added, held as a Field of what emits it, which holds them until they're cancelled. Subscribe gives a Subscription, whose Cancel takes its handler off; a handler subscribed for an owner, which it holds weakly, also goes once the owner does. An Event and its Subscriptions stay on the thread that made them, as a Class's objects do.

    std/events/event.fb

    Types

    Event class

    Public Class Event<T>

    The handlers that an Emit calls with its value, in the order they were added.

    std/events/event.fb, line 100

    • 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.

    Subscription class

    Public Class Subscription

    A handler's place on an Event, which Cancel takes it off. It holds neither the Event nor the handler, so keeping one keeps neither.

    std/events/event.fb, line 203

    • Public Method Cancel() method #

      Takes the handler off its Event, so no Emit after calls it, and lets go of it. Cancelling it again, or once the Event has gone, does nothing.

    • Public Property IsActive: Bool property #

      Whether the handler is still on its Event.

    Report an issue with this page or with FutureBlitz on GitHub.