Documentation
¶
Overview ¶
Package lifecycle is the compiled source for docs/guide/lifecycle-hooks.md.
There are three hooks: mount, event, and teardown. This file is all three.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authorize ¶
Authorize is the event hook. It runs before the reducer for every event, at the single mailbox ingress, so a new event kind cannot skip it.
Returning nil allows the event. A *live.DenyError rejects one event and leaves the connection open. A *live.FatalDenyError rejects it and closes the connection with UNAUTHORIZED (close code 4006). An error of any other shape is treated as a denial, because a hook that failed open by accident is the one failure mode an authorization hook must not have.
func Init ¶
func Init(topic *Topic) func(ctx context.Context, session live.Session[live.AnonymousIdentity]) (State, []live.Effect[live.AnonymousIdentity], error)
Init is the mount hook. It runs once, as the first transition, before the first snapshot, and it returns two things: the session's initial state, and any startup effects.
Registration happens here, synchronously, and the long-running pump is returned as an effect. The order matters: if the pump did the registering, a change published between the mount and the pump's first loop would be missed, and the session would render a value that was already stale.
Values a mount needs from the upgrade request arrive through the context — that is the whole reason there is no Session.Request(), which would keep an *http.Request alive for the connection's life.
func Teardown ¶
Teardown is the unmount hook. It runs after the session actor has exited, with the final state, and it is where a subscription taken at mount is released.
It is optional, and leaving it nil is what leaks. It is not called with a state value when Init itself failed, because there is no final state to hand over.
Types ¶
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic is the application-owned pubsub the session subscribes to at mount and unsubscribes from at teardown.
func (*Topic) WatchEffect ¶
func (t *Topic) WatchEffect() live.Effect[live.AnonymousIdentity]
WatchEffect is the subscription pump the mount hook schedules.
It is a constructor over a concrete live.Effect[live.AnonymousIdentity]: a source, which provenance and metrics see, and a Run closing over the topic. The Run holds the session open for as long as the session lasts, which is what a subscription is, and returns when the library cancels it at shutdown.