struct

Syn::Core::ConditionVariable

Inherits Struct / Value / Object

Synchronize execution of concurrently running fibers.

This can be used to replace polling with a waiting list that can be resumed when resources are available, while still behaving inside a mutually exclusive context: when a waiting fiber is resumed, the lockable will be locked.

Can also be used as a notification system without a lockable. In which case the lockable must be nil (or Pointer(Syn::Lockable).null) and the lockable won't be unlocked nor locked.

Constructors

Instance methods

broadcast

Enqueues all waiting fibers at once. Does nothing if there aren't any waiting fiber.

Source
signal

Enqueues one waiting fiber. Does nothing if there aren't any waiting fiber.

Source
wait(lockable : Pointer(Lockable) | Nil, timeout : Time::Span, *, relock_on_timeout : Bool = true) : Bool

Identical to #wait but the current fiber will be resumed automatically when timeout is reached. Returns true if the timeout was reached, false otherwise.

Source
wait(lockable : Pointer(Lockable) | Nil) : Nil

Suspends the current fiber. The lockable is unlocked before the fiber is suspended (the current fiber must be holding the lock) and will be locked again after the fiber is resumed and before the function returns.

Source