Raxol.Core.Runtime.Subscription (Raxol v0.2.0)
View SourceProvides a way to subscribe to recurring updates and external events.
Subscriptions allow applications to receive messages over time without explicitly requesting them. This is useful for:
- Timer-based updates (animation, polling)
- System events (window resize, focus change)
- External data streams (file changes, network events)
Types of Subscriptions
:interval
- Regular time-based updates:events
- System or component events:file_watch
- File system changes:custom
- Custom event sources
Examples
# Update every second
Subscription.interval(1000, :tick)
# Listen for specific events
Subscription.events([:key_press, :mouse_click])
# Watch a file for changes
Subscription.file_watch("config.json", [:modify, :delete])
# Custom subscription
Subscription.custom(MyEventSource, :start_listening)
Summary
Functions
Creates a custom subscription using a provided event source.
The event source should implement the Raxol.Core.Runtime.EventSource
behaviour.
Creates a subscription for system or component events.
Creates a subscription that watches for file system changes.
Creates a subscription that will send a message at regular intervals.
Creates a new subscription. This is the low-level constructor, prefer using the specific subscription constructors unless you need custom behavior.
Starts a subscription within the given context. This is used by the runtime system and should not be called directly by applications.
Stops a subscription. This is used by the runtime system and should not be called directly by applications.
Types
@type t() :: %Raxol.Core.Runtime.Subscription{ data: term(), type: :interval | :events | :file_watch | :custom }
Functions
Creates a custom subscription using a provided event source.
The event source should implement the Raxol.Core.Runtime.EventSource
behaviour.
Creates a subscription for system or component events.
Event Types
:key_press
- Keyboard events:mouse_click
- Mouse click events:mouse_move
- Mouse movement events:window_resize
- Terminal window resize:focus_change
- Terminal focus change:component
- Component-specific events
Creates a subscription that watches for file system changes.
Event Types
:modify
- File content changes:delete
- File deletion:create
- File creation:rename
- File rename:attrib
- Attribute changes
Creates a subscription that will send a message at regular intervals.
Options
:start_immediately
- Send first message immediately (default: false):jitter
- Add random jitter to interval (default: 0)
Creates a new subscription. This is the low-level constructor, prefer using the specific subscription constructors unless you need custom behavior.
Starts a subscription within the given context. This is used by the runtime system and should not be called directly by applications.
Returns {:ok, subscription_id}
or {:error, reason}
.
Stops a subscription. This is used by the runtime system and should not be called directly by applications.