Control flow methods
There are some helper methods which might be useful when writing code using ox’s concurrency operators:
forever { ... }repeatedly evaluates the given code block foreverrepeatWhile { ... }repeatedly evaluates the given code block, as long as it returnstruerepeatUntil { ... }repeatedly evaluates the given code block, until it returnstrueneverblocks the current thread indefinitely, until it is interruptedcheckInterrupt()checks if the current thread is interrupted, and if so, throws anInterruptedException. Useful in compute-intensive code, which wants to cooperate in the cancellation protocolcede()yields the current (virtual) thread back to the scheduler, allowing other threads to run, and checks for interruption (ascheckInterrupt()does). Useful in compute-intensive code, which doesn’t otherwise call any blocking operations: virtual threads are not preempted, so without yielding, a CPU-bound loop can starve other virtual threads. As a rule of thumb, callcede()about once every millisecond of computation (a single call costs about 1µs). For long-running computations, or code which can’t be instrumented with yields, see CPU-intensive operations.
All of these are inline methods, imposing no runtime overhead.