signals

Typed reactive values and deterministic invalidation for Garnet

Garnet Signals

garnet-signals supplies typed reactive values without a renderer, ECS, clock, or scheduler. All propagation is synchronous on the calling thread. Values are ordinary Crystal values; signal classes provide shared identity, dependency tracking, and monotonically increasing semantic revisions.

require "garnet-signals"

position = Garnet::Signals::State.new(10_f32)
offset = Garnet::Signals::State.new(4_f32)
world = Garnet::Signals::Computed.new { position.get + offset.get }

watch = Garnet::Signals.watch(world) do |value, previous|
  puts "#{previous} -> #{value}"
end

Garnet::Signals.batch do
  position.set(20_f32)
  offset.set(8_f32)
end

watch.close

State#set returns whether the value changed and does not publish equal values. Computed values discover dependencies on each evaluation, replace conditional dependencies, invalidate synchronously, and recompute lazily. Watches run once at the end of a nested batch and must be closed when their owner is finished. Dependency subscriptions are weak, so a source does not keep an abandoned watch or computed value alive.

Constant(T) adapts an immutable value to the same readable interface without introducing a mutable cell or changing revision.

Readable#snapshot returns the current value together with a stable source ID and semantic revision. Consumers such as scene extractors and renderer caches can retain {source_id, revision} and skip work when it is unchanged. The snapshot contains no callback or backend-specific state.

Watch#close and Subscription#close are the teardown calls (closed? reports them); the older dispose and disposed? names remain as deprecated aliases. A computed value that reads itself raises Signals::CycleError, a subclass of Signals::Error < Garnet::Error.

Repository

signals

Owner
Statistic
  • 0
  • 0
  • 0
  • 3
  • 0
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:09:21 GMT

Languages