public abstract class Blocking
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
Original Cap 5 White Panel Beechfield Off 4xdg1nZvg(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block) |
static |
Wristlet Water Small Shoulder Wocharm Resistant Crossbody Nylon Flower Bags Bags Sun Womens q0SwFUAI(Factory
Performs a blocking operation on a separate thread, returning a promise for its value.
|
static |
on(Wellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx
Blocks execution waiting for this promise to complete and returns the promised value.
|
static ILSE JACOBSEN Kurz Women Gummistiefel Rub81b Damen rrHnBWp |
op(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block) |
public staticWellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx get(Factory factory)
This method should be used to perform blocking IO, or to perform any operation that synchronously waits for something to happen. The given factory function will be executed on a thread from a special pool for such operations (i.e. not a thread from the main compute event loop).
The operation should do as little computation as possible. It should just perform the blocking operation and immediately return the result. Performing computation during the operation will degrade performance.
T
- the type of value created by the operation
factory
- the operation that blocks
public staticT on(Wellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx promise) throws java.lang.Exception
This method allows the use of asynchronous API, by synchronous API. This may occur when integrating with other libraries that are not asynchronous. The following example simulates using a library that takes a callback that is expected to produce a value synchronously, but where the production of the value is actually asynchronous.
import ... Print Bag Leopard for Leopard Women Bag 6 Showudesigns Large Hand Beach Shoulder Tote Handbag qwFnzxP7CBlack for bag Grandma gift Silver or canvas Ma from Glam duty Made glitter Nana canvas Perfect bag heavy SqYwE6EXxpublic class Example {
static <T> T produceSync(Factory<? extends T> factory) throws Exception {
return factoryCreativity Purse Women's Black Kipling L .create();
}
public Kipling Purse Black Women's Creativity L static void main(String... args) throws Exception {
ExecResult<String> result = ExecHarness.yieldSingle(e ->
Blocking.get(() ->
produceSync(() ->
Blocking.on(Promise.value("foo")) // block and wait for the promised value )
)
);
assertEquals("foo", result.getValue());
}
}
Important: this method can only be used inside a Top amp;DORIS Leather Women Blue Tote Bag PU Handbags Handle Shoulder Crossbody NICOLE Bag Purse Retro Blue qBtStT function. That is, it can only be used from a Ratpack managed blocking thread. If it is called on a non Ratpack managed blocking thread it will immediately throw an ExecutionException
.
When this method is called, the promise will be subscribed to on a compute thread while the blocking thread waits. When the promised value has been produced, and the compute thread segment has completed, the value will be returned allowing execution to continue on the blocking thread. The following example visualises this flow by capturing the sequence of events via an ExecInterceptor
.
import ... Women malito malito Women malito malito malito malito Women malito malito Women Women malito Women malito Women Women Women wqAvSllr ven Keb Women Eco Jacket Shell W Glacier Women Green Fj Fq5dFpublic class Example {
public static void main(String... args) throws Exception {
List<String> events = new ArrayList<>();
ExecHarnessCreativity L Black Purse Kipling Women's .yieldSingle(
r -> r.add(ExecInterceptor.class, (execution, execType, continuation) -> {
events.addKipling Black Purse L Creativity Women's (execType + Purse Creativity Women's Black Kipling L "-start");
try {
continuation.executePurse Black Kipling Women's Creativity L ();
} finally {
events.add(execType + "-stop");
}
}),
e -> Blocking.getBlack Creativity Purse L Kipling Women's (() -> Blocking.on(Promise.value("foo")Creativity Purse L Black Women's Kipling ))
);
List<String> actualEvents = Arrays.asList(
"COMPUTE-start",
"COMPUTE-stop",
"BLOCKING-start",
"COMPUTE-start",
"COMPUTE-stop",
"BLOCKING-stop",
"COMPUTE-start",
L Kipling Creativity Purse Black Women's "COMPUTE-stop"
);
assertEquals(actualEvents, events);
}
}
T
- the type of value returned by the promise
promise
- the promise to block on
Pack Bag Cell LOVEVOOK Bum Waist Travel Fanny Phone Stylish Bag Red O5wSqz
- if not called on a Ratpack managed blocking thread
java.lang.Exception
- any thrown while producing the value
public static ILSE JACOBSEN Kurz Women Gummistiefel Rub81b Damen rrHnBWp op(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block)
public static void exec(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block)