class
Ktistec::Topic
- Ktistec::Topic
- Reference
- Object
Overview
A pub/sub topic.
Debouncing
Topics support provider-side debouncing for high-frequency subjects. When a subject is configured for debouncing, notifications are batched and delivered after a fixed time window instead of immediately.
Configure debounce using a regex pattern matching subject names:
Ktistec::Topic.configure_debounce(/\/actors\/[^\/]+\/notifications$/, 1.second)
Debounce configuration is in src/controllers/streaming.cr.
Note: Subject names can change at runtime (see .rename_subject).
For example, thread subjects change from object IRI to thread IRI.
Design patterns to match the category of possible names for
a subject.
Debounce behavior:
- First notification starts a timer
- Subsequent notifications during the window are queued
- When timer fires, queued values are delivered at once
- Subjects not matching any pattern are delivered immediately
Defined in:
framework/topic.crConstant Summary
-
Log =
::Log.for(self)
Constructors
Class Method Summary
-
.configure_debounce(pattern : Regex, interval : Time::Span)
Configures debounce for subjects matching
pattern. -
.debounce_interval_for(subject : String) : Time::Span | Nil
Returns the debounce interval for a subject, or
nil. -
.rename_subject(before, after)
Renames a subject across all topics.
-
.reset!
Resets the topic class state.
Instance Method Summary
-
#<<(subject : String)
Adds a subject.
-
#finalize
Removes subjects that no longer belong to any topic.
-
#notify_subscribers(value : String = "")
Notifies subscribers about updates.
-
#subjects
Returns the subjects.
-
#subscribe(timeout : Time::Span | Nil = nil, &)
Subscribes to updates about the topic.
-
#subscriptions
Returns the subscriptions to this topic.
Constructor Detail
Class Method Detail
Configures debounce for subjects matching pattern.
interval is the debounce window.
Returns the debounce interval for a subject, or nil.
Resets the topic class state.
Clears all subscriptions. Clears all subjects.
This is useful when testing. It should not be used in any other context!
Instance Method Detail
Removes subjects that no longer belong to any topic.
Note: this method should only be called during garbage collection.
Notifies subscribers about updates.
Passes an optional value to each subscriber.
Does not block.