public class

Event

extends Object
java.lang.Object
   ↳ net.schmizz.concurrent.Event<T extends java.lang.Throwable>

Class Overview

An event can be set, cleared, or awaited, similar to Python's threading.event. The key difference is that a waiter may be delivered an exception of parameterized type T.

Uses Promise under the hood.

Summary

Fields
private static final Object SOME
private final Promise<Object, T extends Throwable> promise
Public Constructors
Event(String name, ExceptionChainer<T> chainer)
Creates this event with given name and exception chainer.
Event(String name, ExceptionChainer<T> chainer, ReentrantLock lock)
Creates this event with given name, exception chainer, and associated lock.
Public Methods
void await()
Await this event to have a definite true or false value.
void await(long timeout, TimeUnit unit)
Await this event to have a definite true or false value, for timeout duration.
void clear()
Clear this event.
void deliverError(Throwable t)
Deliver the error t (after chaining) to any present or future waiters.
boolean hasWaiters()
boolean inError()
boolean isSet()
void lock()
Acquire the lock associated with this event.
void set()
Sets this event to be true.
String toString()
boolean tryAwait(long timeout, TimeUnit unit)
Await this event to have a definite true or false value, for timeout duration.
void unlock()
Release the lock associated with this event.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final Object SOME

private final Promise<Object, T extends Throwable> promise

Public Constructors

public Event (String name, ExceptionChainer<T> chainer)

Creates this event with given name and exception chainer. Allocates a new java.util.concurrent.locks.Lock Lock object for this event.

Parameters
name Name of this event
chainer ExceptionChainer that will be used for chaining exceptions

public Event (String name, ExceptionChainer<T> chainer, ReentrantLock lock)

Creates this event with given name, exception chainer, and associated lock.

Parameters
name Name of this event
chainer ExceptionChainer that will be used for chaining exceptions
lock Lock to use

Public Methods

public void await ()

Await this event to have a definite true or false value.

Throws
Throwable

public void await (long timeout, TimeUnit unit)

Await this event to have a definite true or false value, for timeout duration.

Parameters
timeout Timeout
unit The time unit for the timeout
Throws
Throwable

public void clear ()

Clear this event. A cleared event !isSet().

public void deliverError (Throwable t)

Deliver the error t (after chaining) to any present or future waiters.

Parameters
t

public boolean hasWaiters ()

Returns
  • whether there are any threads waiting on this event to be set.

public boolean inError ()

Returns
  • whether this event is in an error state i.e. has been delivered an error.

public boolean isSet ()

Returns

public void lock ()

Acquire the lock associated with this event.

public void set ()

Sets this event to be true. Short for set(true).

public String toString ()

public boolean tryAwait (long timeout, TimeUnit unit)

Await this event to have a definite true or false value, for timeout duration.

If the definite value is not available when the timeout expires, returns false.

Parameters
timeout Timeout
unit The time unit for the timeout
Throws
Throwable

public void unlock ()

Release the lock associated with this event.