const classafConcurrent::Synchronized
sys::Obj afConcurrent::Synchronized
Provides synchronized
access to blocks of code. Example usage:
lock := Synchronized(ActorPool()) val := lock.synchronized |->Obj?| {// ...// important stuff// ...return 69 }
- async
Runs the given func asynchronously, using this Synchronized's
ActorPool
.Errs that occur within the block are logged but not rethrown unless you call
get()
on the returnedFuture
.The given func and return value must be immutable.
- inSync
Bool inSync()
Returns
true
if the current thread is running inside the synchronised Actor. E.g.:lock := Synchronized(ActorPool()) lock.inSync
// --> falselock.synchronized |->| { lock.inSync// --> true... }- make
new make(ActorPool actorPool, Duration? timeout := null, |This? f := null)
Create a
Synchronized
class that uses the givenActorPool
and timeout.The default timeout of
null
blocks forever.- reentrant
const Bool reentrant := true
Determines if this synchronised lock is re-entrant or not. Re-entrant locks allow multiple nested calls to
synchronized()
(on this object) without fear of deadlocks.Because re-entrant locks are often considered an indication of bad design, setting
reentrant
tofalse
will disable nested calls tosynchronized()
, throwing an Err instead.Defaults to
true
.- synchronized
This effectively wraps the given func in a Java
synchronized { ... }
block and returns its calculated value.The given func and return value must be immutable.
- timeout
const Duration? timeout
The default timeout to use when waiting for
synchronized
blocks to complete.The default timeout of
null
blocks forever.