Lyricdev
GitHub

class Once

pub class Once

Work done once.

The first Once.run does it, every later one returns at once, and one that comes while it runs waits until it has ended.

Methods

pub static fn new(): Once

Creates a Once whose work is not done yet.

pub fn run<E :: [Error]>(body: fn() -> void throws E): void throws [E, Cancelled]

Runs body if no earlier call has run its work to the end.

Where another task runs the work now, this waits for that one instead.

Errors

Throws what body throws; the work then counts as not done, and the next run runs it again. Throws Cancelled when the task is cancelled during the wait.