/* * Copyright 2021 Jonathan Lindegaard Starup * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Type of lock condition variables, and its functions.///pubmod Concurrent.Condition {import java.lang.IllegalMonitorStateExceptionimport java.util.concurrent.locks.{Condition => JCondition}////// Type of lock condition variables.////// Wraps a Java `Condition`.///pubenumCondition(JCondition)////// Causes the current thread to wait until it is signalled or interrupted.///pubdefawait(condition: Condition): Unit \ IO =let Condition(c) = condition;c.await()////// Causes the current thread to wait until it is signalled or interrupted, or the specified waiting/// time(nanos) elapses. The method returns an estimate of the number of nanoseconds remaining to wait/// given the supplied nanosTimeout value upon return, or a value less than or equal to zero if it timed out.///pubdefawaitTimeout(condition: Condition, timeout: Int64): Int64 \ IO =let Condition(c) = condition;c.awaitNanos(timeout)////// Wakes up one waiting thread.///pubdefsignal(condition: Condition): Result[IllegalMonitorStateException, Unit] \ IO =let Condition(c) = condition;try { Ok(c.signal()) } catch {casee: IllegalMonitorStateException => Err(e) }////// Wakes up all waiting threads.///pubdefsignalAll(condition: Condition): Result[IllegalMonitorStateException, Unit] \ IO =let Condition(c) = condition;try { Ok(c.signalAll()) } catch {casee: IllegalMonitorStateException => Err(e) }}