當前位置: 首頁>>代碼示例>>Java>>正文


Java Action.run方法代碼示例

本文整理匯總了Java中io.reactivex.functions.Action.run方法的典型用法代碼示例。如果您正苦於以下問題:Java Action.run方法的具體用法?Java Action.run怎麽用?Java Action.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.functions.Action的用法示例。


在下文中一共展示了Action.run方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doOnEmpty

import io.reactivex.functions.Action; //導入方法依賴的package包/類
public static <T> FlowableOperator<T, T> doOnEmpty(Action
                                                           action) {
    return new FlowableOperator<T, T>() {
        @Override
        public Subscriber<? super T> apply(Subscriber<? super
                T> subscriber) throws Exception {
            return new DisposableSubscriber<T>() {
                boolean isEmpty = true;

                @Override
                public void onNext(T value) {
                    isEmpty = false;
                    subscriber.onNext(value);
                }

                @Override
                public void onError(Throwable t) {
                    subscriber.onError(t);
                }

                @Override
                public void onComplete() {
                    if (isEmpty) {
                        try {
                            action.run();
                        } catch (Exception e) {
                            onError(e);
                            return;
                        }
                    }
                    subscriber.onComplete();
                }
            };
        }
    };
}
 
開發者ID:PacktPublishing,項目名稱:Learning-RxJava,代碼行數:37,代碼來源:Ch9_9.java

示例2: doOnEmpty

import io.reactivex.functions.Action; //導入方法依賴的package包/類
public static <T> ObservableOperator<T, T> doOnEmpty(Action
                                                             action) {
    return new ObservableOperator<T, T>() {
        @Override
        public Observer<? super T> apply(Observer<? super T>
                                                 observer) throws Exception {
            return new DisposableObserver<T>() {
                boolean isEmpty = true;

                @Override
                public void onNext(T value) {
                    isEmpty = false;
                    observer.onNext(value);
                }

                @Override
                public void onError(Throwable t) {
                    observer.onError(t);
                }

                @Override
                public void onComplete() {
                    if (isEmpty) {
                        try {
                            action.run();
                        } catch (Exception e) {
                            onError(e);
                            return;
                        }
                    }
                    observer.onComplete();
                }
            };
        }
    };
}
 
開發者ID:PacktPublishing,項目名稱:Learning-RxJava,代碼行數:37,代碼來源:Ch9_7.java

示例3: ifNotPresent

import io.reactivex.functions.Action; //導入方法依賴的package包/類
@Nonnull
public RxOptional<T> ifNotPresent(@Nonnull Action action) {
    if (value == null) {
        requireNonNull(action);
        try {
            action.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return this;
}
 
開發者ID:carterhudson,項目名稱:RxOptional,代碼行數:14,代碼來源:RxOptional.java

示例4: invoke

import io.reactivex.functions.Action; //導入方法依賴的package包/類
/**
 * invoke an {@link Action} or throw a {@link RuntimeException}
 *
 * @param action the {@link Action} to invoke
 */
static void invoke(Action action) {
    try {
        action.run();
    } catch (Exception e) {
        throw new RuntimeExceptionConverter().apply(e);
    }
}
 
開發者ID:Ahmed-Adel-Ismail,項目名稱:J-Chain,代碼行數:13,代碼來源:Invoker.java

示例5: onNext

import io.reactivex.functions.Action; //導入方法依賴的package包/類
private void onNext(Action doNotify)
{
    boolean applyingUpdate = _isApplyingUpdate.get();

    _isApplyingUpdate.set(true);

    if (!applyingUpdate) {
        long ticket = _nextTicket.getAndIncrement();

        // ensure ordered
        while (_nowServing.get() != ticket) {
            Thread.yield();
        }
    }

    try {
        doNotify.run();
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }

    if (!applyingUpdate) {
        // allow the next update to take hold
        _nowServing.incrementAndGet();

        _isApplyingUpdate.set(false);
    }
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:30,代碼來源:BaseFlowableList.java

示例6: emitUpdate

import io.reactivex.functions.Action; //導入方法依賴的package包/類
private void emitUpdate(K key, Consumer<Processor<V, V>> updater, Action missHandler, boolean disconnect)
{
    Processor<V, V> subject = null;

    if (disconnect) {
        _writeLock.lock();
    }
    else {
        _readLock.lock();
    }

    try {
        // if we have a subject, we will emit the new value on the subject
        if (_weakSources.containsKey(key)) {
            WeakReference<Processor<V, V>> weakSource = _weakSources.get(key);

            subject = weakSource.get();
        }

        if (disconnect) {
            _weakSources.remove(key);
            _weakCache.remove(key);
            _cache.remove(key);
        }
    }
    finally {
        if (disconnect) {
            _writeLock.unlock();
        }
        else {
            _readLock.unlock();
        }

    }

    try {
        if (subject != null) {
            updater.accept(subject);
        }
        else {
            missHandler.run();
        }
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:48,代碼來源:SubjectMap.java


注:本文中的io.reactivex.functions.Action.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。