Skip to content
FutureBlitz

    Install

    Import std.concurrent.locks

    WaitGroup

    std.concurrent.locks

    class

    Public Shared Class WaitGroup

    A count of the work under way, which Wait waits to see at 0: Add counts work before it starts, and Done says that some is done.

    Examples

    Global finished = Atomic<Int>(0)
    Const work = WaitGroup()
    
    Function Step()
        finished.Add(1)
        work.Done()
    End Function
    
    work.Add(3)
    For i = 1 To 3
        Spawn(Step)
    End For
    
    work.Wait()
    Expect(finished.Load() == 3)

    std/concurrent/locks.fb, line 172

    • Public New() constructor #

      A WaitGroup counting 0.

    • @PanicsAtCaller Public Method Add(count: Int = 1) method #

      Adds count, which can be negative, to the work it counts, and wakes the threads waiting once that's 0. Panics when it would take that below 0, or past what an Int holds.

    • @PanicsAtCaller Public Method Done() method #

      Takes 1 from the count. Panics when it's 0, since Done would be once more than Add counted.

    • Public Method Wait() method #

      Waits until the count is 0, which it may be already.

    • Public Method Wait(cancel: Cancellation) Throws CancelledError method #

      Waits until the count is 0 unless the cancellation is cancelled first, or is already, which throws a CancelledError.

    • Public Property Count: Int property #

      The count now, which other threads may change at any time.

    Report an issue with this page or with FutureBlitz on GitHub.