Search in sources :

Example 21 with Action0

use of rx.functions.Action0 in project Rutgers-Course-Tracker by tevjef.

the class ChooserPresenterImpl method loadSystemMessage.

@Override
public void loadSystemMessage() {
    cancePreviousSubscription();
    Subscriber<SystemMessage> mSubscriber = new Subscriber<SystemMessage>() {

        @Override
        public void onCompleted() {
        //Noop
        }

        @Override
        public void onError(Throwable e) {
        //Noop
        }

        @Override
        public void onNext(SystemMessage systemMessage) {
            if (getView() != null) {
                getView().showMessage(systemMessage);
            }
        }
    };
    mSubsciption = mRetroRutgers.getSystemMessage().doOnSubscribe(new Action0() {

        @Override
        public void call() {
            isLoading = true;
        }
    }).doOnTerminate(new Action0() {

        @Override
        public void call() {
            isLoading = false;
        }
    }).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
Also used : SystemMessage(com.tevinjeffrey.rutgersct.rutgersapi.model.SystemMessage) Action0(rx.functions.Action0) Subscriber(rx.Subscriber)

Example 22 with Action0

use of rx.functions.Action0 in project Conductor by bluelinelabs.

the class RxLifecycleController method onAttach.

@Override
protected void onAttach(@NonNull View view) {
    super.onAttach(view);
    Log.i(TAG, "onAttach() called");
    (((ActionBarProvider) getActivity()).getSupportActionBar()).setTitle("RxLifecycle Demo");
    Observable.interval(1, TimeUnit.SECONDS).doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            Log.i(TAG, "Unsubscribing from onAttach()");
        }
    }).compose(this.<Long>bindUntilEvent(ControllerEvent.DETACH)).subscribe(new Action1<Long>() {

        @Override
        public void call(Long num) {
            Log.i(TAG, "Started in onAttach(), running until onDetach(): " + num);
        }
    });
}
Also used : Action0(rx.functions.Action0) ActionBarProvider(com.bluelinelabs.conductor.demo.ActionBarProvider)

Example 23 with Action0

use of rx.functions.Action0 in project frodo by android10.

the class LogStreamObservable method get.

@Override
<T> Observable<T> get(T type) throws Throwable {
    final StopWatch stopWatch = new StopWatch();
    final Counter emittedItems = new Counter(joinPoint.getMethodName());
    return ((Observable<T>) joinPoint.proceed()).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            stopWatch.start();
        }
    }).doOnNext(new Action1<T>() {

        @Override
        public void call(T value) {
            emittedItems.increment();
            messageManager.printObservableOnNextWithValue(observableInfo, value);
        }
    }).doOnError(new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            messageManager.printObservableOnError(observableInfo, throwable);
        }
    }).doOnTerminate(new Action0() {

        @Override
        public void call() {
            stopWatch.stop();
            observableInfo.setTotalExecutionTime(stopWatch.getTotalTimeMillis());
            observableInfo.setTotalEmittedItems(emittedItems.tally());
            messageManager.printObservableItemTimeInfo(observableInfo);
        }
    });
}
Also used : Action0(rx.functions.Action0) Counter(com.fernandocejas.frodo.internal.Counter) Action1(rx.functions.Action1) StopWatch(com.fernandocejas.frodo.internal.StopWatch)

Example 24 with Action0

use of rx.functions.Action0 in project sqlbrite by square.

the class BriteContentResolver method createQuery.

/**
   * Create an observable which will notify subscribers with a {@linkplain Query query} for
   * execution. Subscribers are responsible for <b>always</b> closing {@link Cursor} instance
   * returned from the {@link Query}.
   * <p>
   * Subscribers will receive an immediate notification for initial data as well as subsequent
   * notifications for when the supplied {@code uri}'s data changes. Unsubscribe when you no longer
   * want updates to a query.
   * <p>
   * Since content resolver triggers are inherently asynchronous, items emitted from the returned
   * observable use the {@link Scheduler} supplied to {@link SqlBrite#wrapContentProvider}. For
   * consistency, the immediate notification sent on subscribe also uses this scheduler. As such,
   * calling {@link Observable#subscribeOn subscribeOn} on the returned observable has no effect.
   * <p>
   * Note: To skip the immediate notification and only receive subsequent notifications when data
   * has changed call {@code skip(1)} on the returned observable.
   * <p>
   * <b>Warning:</b> this method does not perform the query! Only by subscribing to the returned
   * {@link Observable} will the operation occur.
   *
   * @see ContentResolver#query(Uri, String[], String, String[], String)
   * @see ContentResolver#registerContentObserver(Uri, boolean, ContentObserver)
   */
@CheckResult
@NonNull
public QueryObservable createQuery(@NonNull final Uri uri, @Nullable final String[] projection, @Nullable final String selection, @Nullable final String[] selectionArgs, @Nullable final String sortOrder, final boolean notifyForDescendents) {
    final Query query = new Query() {

        @Override
        public Cursor run() {
            long startNanos = nanoTime();
            Cursor cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder);
            if (logging) {
                long tookMillis = NANOSECONDS.toMillis(nanoTime() - startNanos);
                log("QUERY (%sms)\n  uri: %s\n  projection: %s\n  selection: %s\n  selectionArgs: %s\n  " + "sortOrder: %s\n  notifyForDescendents: %s", tookMillis, uri, Arrays.toString(projection), selection, Arrays.toString(selectionArgs), sortOrder, notifyForDescendents);
            }
            return cursor;
        }
    };
    OnSubscribe<Query> subscribe = new OnSubscribe<Query>() {

        @Override
        public void call(final Subscriber<? super Query> subscriber) {
            final ContentObserver observer = new ContentObserver(contentObserverHandler) {

                @Override
                public void onChange(boolean selfChange) {
                    subscriber.onNext(query);
                }
            };
            contentResolver.registerContentObserver(uri, notifyForDescendents, observer);
            subscriber.add(Subscriptions.create(new Action0() {

                @Override
                public void call() {
                    contentResolver.unregisterContentObserver(observer);
                }
            }));
            // Trigger initial query.
            subscriber.onNext(query);
        }
    };
    final Observable<Query> queryObservable = //
    Observable.create(subscribe).onBackpressureLatest().observeOn(//
    scheduler).compose(// Apply the user's query transformer.
    queryTransformer).onBackpressureLatest();
    // TODO switch to .to() when non-@Experimental
    return new QueryObservable(new OnSubscribe<Query>() {

        @Override
        public void call(Subscriber<? super Query> subscriber) {
            queryObservable.unsafeSubscribe(subscriber);
        }
    });
}
Also used : Action0(rx.functions.Action0) Query(com.squareup.sqlbrite.SqlBrite.Query) Subscriber(rx.Subscriber) OnSubscribe(rx.Observable.OnSubscribe) Cursor(android.database.Cursor) ContentObserver(android.database.ContentObserver) CheckResult(android.support.annotation.CheckResult) NonNull(android.support.annotation.NonNull)

Example 25 with Action0

use of rx.functions.Action0 in project realm-java by realm.

the class RxJavaTests method realmList_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmList_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
    realm.commitTransaction();
    Observable<RealmList<Dog>> observable = list.asObservable().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            realm.close();
        }
    });
    subscription = observable.subscribe(new Action1<RealmList<Dog>>() {

        @Override
        public void call(RealmList<Dog> dogs) {
        }
    });
    subscription.unsubscribe();
    assertTrue(realm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) Dog(io.realm.entities.Dog) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

Action0 (rx.functions.Action0)134 Subscription (rx.Subscription)58 Test (org.junit.Test)56 CountDownLatch (java.util.concurrent.CountDownLatch)50 Action1 (rx.functions.Action1)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ArrayList (java.util.ArrayList)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 List (java.util.List)15 Func1 (rx.functions.Func1)13 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)12 Observable (rx.Observable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 OnClick (butterknife.OnClick)10 IOException (java.io.IOException)9 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)8 UiThreadTest (android.support.test.annotation.UiThreadTest)7 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)7 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)7 Method (java.lang.reflect.Method)7