Skip to content
FutureBlitz

    Install

    Import std.concurrent.locks

    Once

    std.concurrent.locks

    class

    Public Shared Class Once

    Work that runs one time: the first Do runs it, and every other, at once or after, on any thread, returns once it has run.

    Examples

    Global runs = Atomic<Int>(0)
    Const setup = Once()
    
    Function CountRun()
        runs.Add(1)
    End Function
    
    Parallel For i = 0 Until 8
        setup.Do(CountRun)
    End For
    
    Expect(runs.Load() == 1 && setup.IsDone)

    std/concurrent/locks.fb, line 241

    • Public New() constructor #

      A new Once, whose work hasn't run.

    • @PanicsAtCaller Public Method Do(work: Func()) method #

      Runs work, unless a Do has, waiting while another thread's Do runs it. Panics in a Do that the work itself calls, which would wait for itself forever.

    • Public Property IsDone: Bool property #

      Whether the work has run.

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