struct Syn::Core::WaitGroup

Overview

Suspend execution until other fibers are finished.

Defined in:

core/wait_group.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(counter : Int32 = 0) #

[View source]

Instance Method Detail

def add(count : Int) : Nil #

Increments the counter by how many fibers we want to wait for.

Can be called at any time, allowing concurrent fibers to add more fibers to wait for, but they must always do so before calling #done to decrement the counter, to make sure that the counter may never inadvertently reach zero before all fibers are done.


[View source]
def done : Nil #

Decrements the counter by one. Must be called by concurrent fibers once they have finished processing. When the counter reaches zero, all waiting fibers will be resumed.


[View source]
def wait(timeout : Time::Span) : Bool #

Same as #wait but only waits until timeout is reached. Returns true if the counter reached zero; returns false if timeout was reached.

EXPERIMENTAL The timeout feature is experimental.


[View source]
def wait : Nil #

Suspends the current fiber until the counter reaches zero, at which point the fiber will be closed.

Can be called from different fibers.


[View source]