- java.lang.Object
-
- swim.concurrent.Sync<T>
-
- All Implemented Interfaces:
ForkJoinPool.ManagedBlocker
,Cont<T>
public class Sync<T> extends Object implements Cont<T>, ForkJoinPool.ManagedBlocker
ACont
inuation whose completion can be synchronously awaited. ASync
continuation is used to await the completion of an asynchronous operation.
-
-
Constructor Summary
Constructors Constructor Description Sync()
Constructs a newSync
continuation that awaits a value of typeT
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
await()
Waits an unbounded amount of time for thisSync
continuation to complete.T
await(long timeout)
Waits a maximum oftimeout
milliseconds for thisSync
continuation to complete.void
bind(T value)
Invoked when the asynchronous operation completes with avalue
.boolean
block()
boolean
isReleasable()
void
trap(Throwable error)
Invoked when the asynchronous operation fails with anerror
.
-
-
-
Method Detail
-
isReleasable
public boolean isReleasable()
- Specified by:
isReleasable
in interfaceForkJoinPool.ManagedBlocker
-
block
public boolean block() throws InterruptedException
- Specified by:
block
in interfaceForkJoinPool.ManagedBlocker
- Throws:
InterruptedException
-
bind
public void bind(T value)
Description copied from interface:Cont
Invoked when the asynchronous operation completes with avalue
.
-
trap
public void trap(Throwable error)
Description copied from interface:Cont
Invoked when the asynchronous operation fails with anerror
.
-
await
public T await(long timeout) throws InterruptedException
Waits a maximum oftimeout
milliseconds for thisSync
continuation to complete. Performs a managed block to avoid thread starvation while waiting.- Throws:
SyncException
- if thetimeout
milliseconds elapses and thisSync
continuation still hasn't been completed.InterruptedException
-
await
public T await() throws InterruptedException
Waits an unbounded amount of time for thisSync
continuation to complete. Performs a managed block to avoid thread starvation while waiting.- Throws:
InterruptedException
-
-