Java Code Examples for rx.functions.Func0#call()
The following examples show how to use
rx.functions.Func0#call() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledServiceTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
private static void assertTryUntil(Func0<Boolean> callback) { int maxIters = 50; // 50 * 100ms == Max 5000ms int iters = 0; while (true) { if (callback.call()) { assertTrue(true); break; } else { if (iters++ <= maxIters) { try { Thread.sleep(100); } catch (Exception ex) { throw new RuntimeException(ex); } } else { assertTrue(false); } } } }
Example 2
Source File: ObservableHelper.java From azure-cosmosdb-java with MIT License | 5 votes |
static public <T> Single<T> inlineIfPossible(Func0<Single<T>> function, IRetryPolicy retryPolicy) { if (retryPolicy == null) { // shortcut return function.call(); } else { return BackoffRetryUtility.executeRetry(function, retryPolicy); } }
Example 3
Source File: RxHelper.java From sfs with Apache License 2.0 | 5 votes |
public static <T> Observable<T> onErrorResumeNext(int count, Func0<Observable<T>> func0) { Observable<T> base = func0.call(); for (int i = 1; i <= count; i++) { base = base.onErrorResumeNext(throwable -> Defer.aVoid() .delay(100, TimeUnit.MILLISECONDS) .flatMap(aVoid -> func0.call())); } return base; }
Example 4
Source File: RxHelper.java From sfs with Apache License 2.0 | 5 votes |
public static <T> Observable<T> onErrorResumeNextExponential(int delay, int retry, Func0<Observable<T>> func0) { Observable<T> base = func0.call(); for (int i = 1; i <= retry; i++) { long d = 2 ^ i * delay; base = base.onErrorResumeNext(throwable -> Defer.aVoid() .delay(d, TimeUnit.MILLISECONDS) .flatMap(aVoid -> func0.call())); } return base; }
Example 5
Source File: Optional.java From RxJava-Optional with Apache License 2.0 | 5 votes |
public <X extends Throwable> T orElseThrow(Func0<? extends X> other) throws X { if (!isPresent()) { throw other.call(); } return get(); }
Example 6
Source File: SwingUtilities2.java From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 | 5 votes |
public static <T> T executeOnAwtEdt(Func0<T> function) throws InvocationTargetException, InterruptedException { if (SwingUtilities.isEventDispatchThread()) { return function.call(); } else { AtomicReference<T> resultRef = new AtomicReference<>(); SwingUtilities.invokeAndWait(() -> resultRef.set(function.call())); return resultRef.get(); } }
Example 7
Source File: FileBasedSPSCQueueMemoryMapped.java From rxjava-extras with Apache License 2.0 | 5 votes |
public FileBasedSPSCQueueMemoryMapped(Func0<File> factory, int size, DataSerializer<T> serializer) { Preconditions.checkNotNull(factory); Preconditions.checkNotNull(serializer); this.factory = factory; this.size = size; this.serializer = serializer; File file = factory.call(); this.writer = new FileBasedSPSCQueueMemoryMappedReaderWriter<T>(file, size, serializer); this.reader = writer.openForWrite().openForRead(); // store store barrier wip.lazySet(0); }
Example 8
Source File: DocumentProducer.java From azure-cosmosdb-java with MIT License | 4 votes |
public DocumentProducer( IDocumentQueryClient client, String collectionResourceId, FeedOptions feedOptions, Func3<PartitionKeyRange, String, Integer, RxDocumentServiceRequest> createRequestFunc, Func1<RxDocumentServiceRequest, Observable<FeedResponse<T>>> executeRequestFunc, PartitionKeyRange targetRange, String collectionLink, Func0<IDocumentClientRetryPolicy> createRetryPolicyFunc, Class<T> resourceType , UUID correlatedActivityId, int initialPageSize, // = -1, String initialContinuationToken, int top) { this.client = client; this.collectionRid = collectionResourceId; this.createRequestFunc = createRequestFunc; this.fetchSchedulingMetrics = new SchedulingStopwatch(); this.fetchSchedulingMetrics.ready(); this.fetchExecutionRangeAccumulator = new FetchExecutionRangeAccumulator(targetRange.getId()); this.executeRequestFuncWithRetries = request -> { retries = -1; this.fetchSchedulingMetrics.start(); this.fetchExecutionRangeAccumulator.beginFetchRange(); IDocumentClientRetryPolicy retryPolicy = null; if (createRetryPolicyFunc != null) { retryPolicy = createRetryPolicyFunc.call(); } final IDocumentClientRetryPolicy finalRetryPolicy = retryPolicy; return ObservableHelper.inlineIfPossibleAsObs( () -> { if (finalRetryPolicy != null) { finalRetryPolicy.onBeforeSendRequest(request); } ++retries; return executeRequestFunc.call(request); }, retryPolicy); }; this.correlatedActivityId = correlatedActivityId; this.feedOptions = feedOptions != null ? new FeedOptions(feedOptions) : new FeedOptions(); this.feedOptions.setRequestContinuation(initialContinuationToken); this.lastResponseContinuationToken = initialContinuationToken; this.resourceType = resourceType; this.targetRange = targetRange; this.collectionLink = collectionLink; this.createRetryPolicyFunc = createRetryPolicyFunc; this.pageSize = initialPageSize; this.top = top; }
Example 9
Source File: Optional.java From RxJava-Optional with Apache License 2.0 | 4 votes |
public T orElseCall(Func0<? extends T> other) { return isPresent() ? get() : other.call(); }
Example 10
Source File: ObservableServerSocket.java From rxjava-extras with Apache License 2.0 | 4 votes |
private static ServerSocket createServerSocket( Func0<? extends ServerSocket> serverSocketCreator, long timeoutMs) throws IOException { ServerSocket s = serverSocketCreator.call(); s.setSoTimeout((int) timeoutMs); return s; }