@Override public Completable call(final T t) { return Completable.fromAction( new Action0() { @Override public void call() { action.call(t); } }); } },
public Completable deleteAllExcluding(List<String> ids) { return Completable.fromAction( () -> database.deleteAllExcluding(Notification.class, "ownerId", ids)); }
public Completable delete(String[] keys) { return Completable.fromAction( () -> database.deleteAllIn(Notification.class, Notification.KEY, keys)); }
@Override public Completable afterPostRunAsync(final boolean isGroupFaulted) { if (!isGroupFaulted) { isInCreateMode = false; initializeKuduClient(); } return Completable.fromAction(new Action0() { @Override public void call() { normalizeProperties(); } }); }
public Completable remove(String md5) { return Completable.fromAction(() -> downloadAccessor.delete(md5)); }
@Override public Completable startDownload(Download download) { return Completable.fromAction(() -> { download.setOverallDownloadStatus(Download.IN_QUEUE); download.setTimeStamp(System.currentTimeMillis()); downloadsRepository.save(download); appDownloaderMap.put(download.getMd5(), createAppDownloadManager(download)); }); }
doAnswer(invocation -> Completable.fromAction(() -> { Object[] arguments = invocation.getArguments(); if (arguments != null .save(Matchers.<Event>any()); doAnswer(invocation -> Completable.fromAction(() -> { Object[] arguments = invocation.getArguments(); if (arguments != null
@Test public void testInterrupt() throws InterruptedException { final int count = 1000; CountDownLatch latch = new CountDownLatch(count); for (int i = 0; i < count; i++) { Completable.complete() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) // The problem does not occur if you comment out this line .andThen(Completable.fromAction(() -> { try { Thread.sleep(3000); } catch (InterruptedException e) { System.out.println("Interrupted!"); // This is output periodically } })) .subscribe(() -> latch.countDown()); } latch.await(); //testInterrupt(); } }
@Test public void test() throws Exception { System.out.println("Testing Completable.concat"); System.out.println(); Completable.concat( Observable.range(1, 5).map(integer -> Completable.fromAction(() -> { try { System.out.println("Processing " + integer + "..."); Thread.sleep(100); System.out.println("Processing " + integer + " finished"); } catch (InterruptedException e) { e.printStackTrace(); } }) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from " + integer)) .subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()) ) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from parent observable")) ).subscribe(() -> { System.out.println("Finished Completable.concat"); }, Throwable::printStackTrace ); Thread.sleep(2000); } }
@Test public void dispatch_completable() { SimpleStore<String> store = new SimpleStore<>("test1"); CompletableDispatcher dispatcher = new CompletableDispatcher(); TestSubscriber<String> testSubscriber = new TestSubscriber<>(); ObservableAdapter.observable(store).subscribe(testSubscriber); final boolean[] completableCalled = new boolean[1]; dispatcher.dispatch(rx.Completable.fromAction(new Action0() { @Override public void call() { completableCalled[0] = true; } })); testSubscriber.assertValues("test1"); assertTrue(completableCalled[0]); } }
private Completable refreshAsync(RxDocumentServiceRequest request) { // TODO System.Diagnostics.Debug.Assert(request.IsNameBased); String resourceFullName = PathsHelper.getCollectionPath(request.getResourceAddress()); Completable completable = null; if (request.requestContext.resolvedCollectionRid != null) { // Here we will issue backend call only if cache wasn't already refreshed (if whatever is there corresponds to previously resolved collection rid). DocumentCollection obsoleteValue = new DocumentCollection(); obsoleteValue.setResourceId(request.requestContext.resolvedCollectionRid); completable = this.collectionInfoByNameCache.getAsync( resourceFullName, obsoleteValue, () -> { Single<DocumentCollection> collectionObs = this.getByNameAsync(resourceFullName); return collectionObs.doOnSuccess(collection -> { this.collectionInfoByIdCache.set(collection.getResourceId(), collection); }); }).toCompletable(); } else { // In case of ForceRefresh directive coming from client, there will be no ResolvedCollectionRid, so we // need to refresh unconditionally. completable = Completable.fromAction(() -> this.refresh(request.getResourceAddress())); } return completable.doOnCompleted(() -> request.requestContext.resolvedCollectionRid = null); }
if (request.isForceNameCacheRefresh()) { Completable completable = this.refreshAsync(request); init = completable.andThen(Completable.fromAction(() -> request.setForceNameCacheRefresh(false)));