Documentation
¶
Overview ¶
Package stream follows a session's events live: the WebSocket with the bearer token, resumed from the last sequence number after a drop, with a fall back to polling the events endpoint when WebSockets are blocked.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStop = errors.New("stop following")
ErrStop is returned by a handler to end the follow cleanly.
Functions ¶
func Follow ¶
func Follow(ctx context.Context, c *api.Client, id string, o Options, handle func(api.Event) error) error
Follow delivers every event after o.Since to handle, in order, until handle returns an error (ErrStop ends it cleanly: Follow then returns nil), ctx ends, or a failure that retrying can't fix (not signed in, no access) happens.
Types ¶
type Options ¶
type Options struct {
// Since is the last sequence number already seen; only later events are delivered.
Since int
// Backoff is the wait before reconnect attempt n (0-based). Default 0.5 s doubling to 15 s.
Backoff func(n int) time.Duration
// Sleep waits d or until ctx ends. Default api.SleepContext.
Sleep func(context.Context, time.Duration) error
// MaxDialFailures is how many connections in a row may fail before polling takes over.
MaxDialFailures int
// PollInterval is the polling fall back's period. Default 3 s.
PollInterval time.Duration
// Notice reports reconnects and the fall back (one line, no newline).
Notice func(string)
// PingEvery keeps an idle connection honest. Zero: 25 s.
PingEvery time.Duration
}
Options tune a Follow.