当前位置: 首页>>代码示例>>Java>>正文


Java SyncOnSubscribe类代码示例

本文整理汇总了Java中rx.observables.SyncOnSubscribe的典型用法代码示例。如果您正苦于以下问题:Java SyncOnSubscribe类的具体用法?Java SyncOnSubscribe怎么用?Java SyncOnSubscribe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SyncOnSubscribe类属于rx.observables包,在下文中一共展示了SyncOnSubscribe类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: adapt

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Override
public Observable<T> adapt(final Call<T> call) {

    return Observable.<T>create(SyncOnSubscribe.createSingleState(new Func0<Call<T>>() {
        @Override
        public Call<T> call() {
            return call.clone();
        }
    }, new Action2<Call<T>, Observer<? super T>>() {
        @Override
        public void call(Call<T> callClone, Observer<? super T> observer) {
            try {
                observer.onNext(callClone.execute());
                observer.onCompleted();
            } catch (Throwable throwable) {
                observer.onError(throwable);
            }
        }
    }, new Action1<Call<T>>() {
        @Override
        public void call(Call<T> tCall) {
            tCall.cancel();
        }
    }));
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:26,代码来源:RxCallAdapter.java

示例2: clearCacheFolder

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public static Observable<Boolean> clearCacheFolder(final String... paths) {
    return Observable
            .create(new SyncOnSubscribe<Integer, Boolean>() {
                @Override
                protected Integer generateState() {
                    return 1;
                }

                @Override
                protected Integer next(Integer state, Observer<? super Boolean> observer) {
                    if (state > 0) {
                        for (String path : paths) {
                            deleteFolderFile(path, false);
                        }
                        observer.onNext(true);
                        observer.onCompleted();
                    }
                    return -1;
                }
            })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:24,代码来源:CacheManager.java

示例3: createSyncOnSubscribe

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@NonNull
private static SyncOnSubscribe<ByteBuffer, byte[]> createSyncOnSubscribe(final byte[] bytes, final int maxBatchSize) {
    return SyncOnSubscribe.createSingleState(
            new Func0<ByteBuffer>() {
                @Override
                public ByteBuffer call() {
                    return ByteBuffer.wrap(bytes);
                }
            },
            new Action2<ByteBuffer, Observer<? super byte[]>>() {
                @Override
                public void call(ByteBuffer byteBuffer, Observer<? super byte[]> observer) {
                    int nextBatchSize = Math.min(byteBuffer.remaining(), maxBatchSize);
                    if (nextBatchSize == 0) {
                        observer.onCompleted();
                        return;
                    }
                    final byte[] nextBatch = new byte[nextBatchSize];
                    byteBuffer.get(nextBatch);
                    observer.onNext(nextBatch);
                }
            }
    );
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:25,代码来源:ByteArrayBatchObservable.java

示例4: observable

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Override
public Observable<T> observable() {
    return Observable.create(new SyncOnSubscribe<CloseableIterator<T>, T>() {
        @Override
        protected CloseableIterator<T> generateState() {
            try {
                return mCallable.call();
            } catch (Exception e) {
                throw new AlchemyException(e);
            }
        }

        @Override
        protected CloseableIterator<T> next(CloseableIterator<T> state, Observer<? super T> observer) {
            if (!state.hasNext()) {
                observer.onCompleted();
                state.close();
                return state;
            }
            observer.onNext(state.next());
            return state;
        }
    });
}
 
开发者ID:DanielSerdyukov,项目名称:alchemy,代码行数:25,代码来源:RxJavaFetchable.java

示例5: createServerSocketObservable

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
private static Observable<Observable<byte[]>> createServerSocketObservable(
        ServerSocket serverSocket, final long timeoutMs, final int bufferSize,
        final Action0 preAcceptAction, final Func1<? super Socket, Boolean> acceptSocket) {
    return Observable.create( //
            SyncOnSubscribe.<ServerSocket, Observable<byte[]>> createSingleState( //
                    Functions.constant0(serverSocket), //
                    new Action2<ServerSocket, Observer<? super Observable<byte[]>>>() {

                        @Override
                        public void call(ServerSocket ss,
                                Observer<? super Observable<byte[]>> observer) {
                            acceptConnection(timeoutMs, bufferSize, ss, observer,
                                    preAcceptAction, acceptSocket);
                        }
                    }));
}
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:17,代码来源:ObservableServerSocket.java

示例6: read

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public <T> Observable<T> read(final Class<T> cls, final Input input, final int bufferSize) {

            return Observable.create(new SyncOnSubscribe<Input,T>() {

                @Override
                protected Input generateState() {
                    return input;
                }

                @Override
                protected Input next(Input arg0, Observer<? super T> observer) {
                    if (input.eof()) {
                        observer.onCompleted();
                    } else {
                        T t = kryo.readObject(input, cls);
                        observer.onNext(t);
                    }
                    return input;
                }
            });
        }
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:22,代码来源:Serialized.java

示例7: create

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Beta
public static <S, T> Observable<T> create(SyncOnSubscribe<S, T> syncOnSubscribe) {
    return new Observable(hook.onCreate(syncOnSubscribe));
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:5,代码来源:Observable.java

示例8: create

import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public static <S, T> ReactiveSeq<T> create(SyncOnSubscribe<S, T> syncOnSubscribe) {
    return reactiveSeq(Observable.create(syncOnSubscribe));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:4,代码来源:Observables.java


注:本文中的rx.observables.SyncOnSubscribe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。