Godot::Channel
Inherits Godot::RefCounted < Godot::Object < Reference < Object
A thread-safe, actor-style communication channel bridging Crystal OS threads, cooperative gameplay fibers, Godot C++ threads, and GDScript coroutines.
Inherits from Godot::RefCounted and registers with ClassDB as GodotChannel.
Concurrency Invariant:
In Crystal 1.20+, raw OS threads (Thread.new) do not possess a fiber execution context
(Fiber#execution_context is nil). Attempting to suspend an empty unbuffered Crystal
Channel(T) on an OS thread raises NilAssertionError. Godot::Channel guarantees
safety across all threads by utilizing native OS synchronization (Thread::Mutex +
Thread::ConditionVariable) and cooperative yielding (Fiber.yield) on the Main Thread.
Constructors
Instance methods
Dispatches generic virtual methods and ClassDB method calls with raw arguments and return buffer
Cooperatively awaits an item from the channel inside a Crystal gameplay fiber.
Yields execution slices via Fiber.yield each frame, preventing engine starvation.
Receives an item from the channel, blocking the calling thread until an item is available.
Safe for background OS worker threads (Thread.new, WorkerThreadPool).
Do NOT call this on Godot's Main Thread; use #try_receive or #await_receive instead!
Sends an item into the channel, blocking if the channel is full until space becomes available.
Returns true on success, or false if the channel was closed.
Automatically dispatches signal received on Godot's Main Thread via call_deferred.
Non-blocking receive operation.
Returns the next queued item, or nil if the channel is empty.
Safe to call anywhere, including in _process or timer callbacks on the Main Thread.
Sends an item into the channel without blocking. Returns true if successfully enqueued, or false if full or closed.