Package com.couchbase.client.core.utils
Class Blocking
- java.lang.Object
-
- com.couchbase.client.core.utils.Blocking
-
@Uncommitted @Private public class Blocking extends Object
Contains various utility methods related to blocking operations. Note that this class has been moved over from "java-client" into "core-io" in the 1.3.0 timeframe. On earlier versions, it's counterpart can be found in the "java-client" library which depends on "core-io".- Since:
- 1.3.0
- Author:
- Michael Nitschinger
-
-
Constructor Summary
Constructors Constructor Description Blocking()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
blockForSingle(rx.Observable<? extends T> observable, long timeout, TimeUnit tu)
Blocks on anObservable
and returns a single event or throws anException
.
-
-
-
Method Detail
-
blockForSingle
public static <T> T blockForSingle(rx.Observable<? extends T> observable, long timeout, TimeUnit tu)
Blocks on anObservable
and returns a single event or throws anException
. Note that when this method is used, only the first item emitted will be returned. The caller needs to make sure that the sourceObservable
only ever returns a single item (or none). TheBlockingObservable
code applies different operators like single, last, first and more, these need to be applied manually. This code is based onBlockingObservable.blockForSingle(rx.Observable<? extends T>)
, but does not wait forever. Instead, it utilizes the internalCountDownLatch
to optimize the timeout case, with less GC and CPU overhead than chaining in anObservable.timeout(long, TimeUnit)
operator. If an error happens inside theObservable
, it will be raised as anException
. If the timeout kicks in, aTimeoutException
nested in aRuntimeException
is thrown to be fully compatible with theObservable.timeout(long, TimeUnit)
behavior.- Type Parameters:
T
- the type returned.- Parameters:
observable
- the sourceObservable
timeout
- the maximum timeout before an exception is thrown.tu
- the timeout unit.- Returns:
- the extracted value from the
Observable
or throws in an error case.
-
-