class Godot::BoundSignal

Overview

Represents a signal bound to a specific Godot object instance. Enables first-class signal handling, inspection, connection, emission, and non-blocking #await.

Examples:

await(enemy.died)
await(enemy.died, timeout_sec: 2.0)
enemy.died.await
enemy.health_changed.connect { |cur, max| puts "Health: #{cur}/#{max}" }

Direct Known Subclasses

Defined in:

lapis/cs_extras/signal_operators.cr
lapis/extras/operators.cr
libgodot/signals/bound_signal.cr

Constructors

Instance Method Summary

Instance methods inherited from class Object

try?(&)
try?
try?

Constructor Detail

def self.new(target : Godot::Object, name : String) #

Instance Method Detail

def +(proc : Proc(Array(Variant), R)) : self forall R #

Operator #+ syntactic sugar for #connect with a Proc (supports sig += ->handler)


def +(proc : Proc(T, R)) : self forall T, R #

Operator #+ for 1-argument typed Proc (supports sig += ->(player : Player) { ... })


def +(proc : Proc(T0, T1, R)) : self forall T0, T1, R #

Operator #+ for 2-argument typed Proc (supports sig += ->(player : Player, sword : Sword) { ... })


def +(proc : Proc(R)) : self forall R #

Operator #+ syntactic sugar for #connect with a 0-argument Proc (supports sig += ->handler)


def +(sub : SignalSubscription) : self #

Operator #+ syntactic sugar accepting a SignalSubscription directly


def -(proc : Proc) : self #

Operator #- syntactic sugar for disconnecting a Proc (supports sig -= ->handler)


def -(sub : SignalSubscription) : self #

Operator #- syntactic sugar for disconnecting a SignalSubscription (supports sig -= sub)


def <<(&block : Array(Variant) -> Void) : SignalSubscription #

Operator << syntactic sugar for #connect with a block


def <<(proc : Proc(Array(Variant), R)) : SignalSubscription forall R #

Operator << syntactic sugar for #connect with a Proc


def <<(proc : Proc(R)) : SignalSubscription forall R #

Operator << syntactic sugar for #connect with a 0-argument Proc


def >(proc : Proc(Array(Variant), R)) : SignalSubscription forall R #

Strict pipe (>) to a Proc accepting raw Variant array or 0-arg Proc


def >(proc : Proc(R)) : SignalSubscription forall R #

def >(target_signal : BoundSignal) : SignalSubscription #

Strict pipe (>): Dispatches to target signal passing raw arguments


def >>(target_signal : TypedSignal(*U)) : SignalSubscription forall U #

Loose pipe (>>) to a strongly-typed TypedSignal(*U) with automatic downcasting & arity adaptation


def >>(proc : Proc(Array(Variant), R)) : SignalSubscription forall R #

Loose pipe (>>) to a Proc accepting raw Variant array


def >>(proc : Proc(*U, R)) : SignalSubscription forall U, R #

Loose pipe (>>) to any N-argument typed Proc(*U, R) with automatic arity trimming, polymorphic downcasting, and numeric coercion.


def >>(target_signal : BoundSignal) : SignalSubscription #

Loose / adaptive pipe (>>): Dispatches with arity trimming and type downcasting


def >>(receiver_method : Tuple(Godot::Object, String | Symbol)) : SignalSubscription #

Loose pipe (>>) to a target object and method tuple: sig >> {target, :on_event}


def active? : Bool #

Returns true if the bound object is active and not destroyed


def alive? : Bool #

Returns true if the bound object is still alive in ObjectDB


def await(timeout_sec : Float64 | Nil = nil) : AwaitStatus(Array(Variant)) #

Cooperatively awaits this signal without blocking the engine main loop. Returns an AwaitStatus(Array(Variant)) indicating completion or timeout.


def await(timeout_sec : Number) : AwaitStatus(Array(Variant)) #

Cooperatively awaits this signal with timeout in seconds


def await!(timeout_sec : Float64 | Nil = nil) : Array(Variant) #

Cooperatively awaits this signal, returning the emitted arguments as Array(Variant), or raising Godot::TimeoutError if timeout_sec expires.


def await!(timeout_sec : Number) : Array(Variant) #

def await?(timeout_sec : Float64 | Nil = nil) : Array(Variant) | Nil #

Cooperatively awaits this signal, returning Array(Variant)?, or nil if timeout_sec expires.


def await?(timeout_sec : Number) : Array(Variant) | Nil #

def clear : self #

Fluent alias for disconnect_all


def connect(flags : ConnectFlags = ConnectFlags::None, callback : Proc(Array(Variant), Void) | Nil = nil, receiver : Godot::Object | Nil = nil) : SignalSubscription #

Connects a callback proc to this signal


def connect(flags : ConnectFlags = ConnectFlags::None, receiver : Godot::Object | Nil = nil, &block : Array(Variant) -> Void) : SignalSubscription #

Connects a callback block to this signal (supports 1-arg |args| and 0-arg blocks)


def connect(receiver : Godot::Object, flags : ConnectFlags = ConnectFlags::None, &block : Array(Variant) -> Void) : SignalSubscription #

Connects a callback block to this signal with explicit receiver tracking as first positional argument


def connect(type0 : T0.class, flags : ConnectFlags = ConnectFlags::None, &block : T0 -> Void) : SignalSubscription forall T0 #

Connects with 1 positional type filter


def connect(type0 : T0.class, type1 : T1.class, flags : ConnectFlags = ConnectFlags::None, &block : T0, T1 -> Void) : SignalSubscription forall T0, T1 #

Connects with 2 positional type filters


def connect(listener_target : Godot::Object, method_name : Symbol, flags : ConnectFlags = ConnectFlags::None) : SignalSubscription #

Connects this signal to a method call on a target object by symbol name


def connect_one_shot(&block : Array(Variant) -> Void) : SignalSubscription #

Backwards-compatibility helper redirecting to ConnectFlags::OneShot


def connected? : Bool #

Returns true if this signal currently has any active subscribers


def connection_count : Int32 #

Returns the count of active subscriptions for this signal


def disconnect : self #

Disconnects all active subscriptions for this signal on the target


def disconnect_all : self #

Disconnects all active subscriptions for this signal on the target (alias)


def emit(*args) : self #

Emits this signal on the target object


def has_connections? : Bool #

Alias to #connected?


def name : String #

def once(type0 : T0.class, type1 : T1.class, &block : T0, T1 -> Void) : SignalSubscription forall T0, T1 #

One-shot listener with 2 positional type filters


def once(type0 : T0.class, &block : T0 -> Void) : SignalSubscription forall T0 #

One-shot listener with 1 positional type filter


def once(&block : Array(Variant) -> Void) : SignalSubscription #

Idiomatic shorthand alias for #connect_one_shot


def pipe_to(target_signal : BoundSignal, strict : Bool = false) : SignalSubscription #

Pipes this signal to target signal


def target : Godot::Object #

def target_id : UInt64 #

Returns the target's 64-bit instance ID (or Crystal object_id for unparented Crystal nodes)


def to_s(io : IO) : Void #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>