• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BehaviorSubject类的典型用法代码示例

java 7次浏览

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

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

示例1: getAutoPlaylistSongs

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
private Observable<List<Song>> getAutoPlaylistSongs(AutoPlaylist playlist) {
    BehaviorSubject<List<Song>> subject;

    if (mPlaylistContents.containsKey(playlist)) {
        subject = mPlaylistContents.get(playlist);
    } else {
        subject = BehaviorSubject.create();
        mPlaylistContents.put(playlist, subject);

        playlist.generatePlaylist(mMusicStore, this, mPlayCountStore)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        subject.observeOn(Schedulers.io())
                .subscribe(contents -> {
                    MediaStoreUtil.editPlaylist(mContext, playlist, contents);
                }, throwable -> {
                    Timber.e(throwable, "Failed to save playlist contents");
                });
    }

    return subject.asObservable();
}
 

开发者ID:marverenic,
项目名称:Jockey,
代码行数:24,
代码来源:LocalPlaylistStore.java

示例2: behaviourSubject

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
public static void behaviourSubject() {
    BehaviorSubject<Integer> subject = BehaviorSubject.create();
    subject.onNext(5);

    Action1<Integer> action1 = integer -> Log.i("From action1", String.valueOf(integer));
    Subscription subscription1 = subject.subscribe(action1);
    subject.onNext(10);

    Action1<Integer> action2 = integer -> Log.i("From action2", String.valueOf(integer));
    Subscription subscription2 = subject.subscribe(action2);
    subject.onNext(20);

    subscription1.unsubscribe();
    subject.onNext(40);

    subscription2.unsubscribe();
    subject.onNext(80);
}
 

开发者ID:ArturVasilov,
项目名称:RxSamplesPractice,
代码行数:19,
代码来源:Samples.java

示例3: shouldEmitErrorAfterViewIsAttached

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void shouldEmitErrorAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewReplayTransformer<Object> transformer = new WaitViewReplayTransformer<>(
            view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
    Observable.error(new RuntimeException())
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertError(RuntimeException.class);
}
 

开发者ID:alapshin,
项目名称:arctor,
代码行数:16,
代码来源:WaitViewReplayTransformerTest.java

示例4: shouldEmitValueAfterViewIsAttached

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void shouldEmitValueAfterViewIsAttached() {
    TestScheduler testScheduler = Schedulers.test();
    BehaviorSubject<Boolean> view = BehaviorSubject.create();
    view.onNext(true);
    WaitViewLatestTransformer<Integer> transformer =
            new WaitViewLatestTransformer<>(view.delay(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS, testScheduler));
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(0)
            .compose(transformer)
            .subscribe(testSubscriber);
    testScheduler.advanceTimeBy(EMIT_DELAY_IN_SECONDS, TimeUnit.SECONDS);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertValue(0);
    testSubscriber.assertCompleted();
}
 

开发者ID:alapshin,
项目名称:arctor,
代码行数:17,
代码来源:WaitViewLatestTransformerTest.java

示例5: testExceptionSubjectAction

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
public void testExceptionSubjectAction() {
    // test the behavior of surfacing exceptions from a subject


    BehaviorSubject<Integer> subject = BehaviorSubject.create();

    final List<Notification<Integer>> notifications = new ArrayList<Notification<Integer>>(4);

    Subscription s = subject.subscribe(new Action1<Integer>() {
        @Override
        public void call(Integer t) {
            notifications.add(Notification.createOnNext(t));
            throw new RuntimeException("call " + t);
        }
    });

    try {
        subject.onNext(0);
        // (unreachable) expect an exception to be thrown
        fail();
    } catch (RuntimeException e) {
        assertEquals("call 0", e.getMessage());
    }
}
 

开发者ID:nextopio,
项目名称:nextop-client,
代码行数:25,
代码来源:RxExceptionTest.java

示例6: getUpdates

点赞 3

import rx.subjects.BehaviorSubject; //导入依赖的package包/类
private BehaviorSubject<ParseChange<P>> getUpdates(I unit) {
    final FileObject resource = unit.source();
    final FileName name = resource.getName();

    // THREADING: it is possible that two different threads asking for a subject may do the parsing twice here, as
    // this is not an atomic operation. However, the chance is very low and it does not break anything (only
    // duplicates some work), so it is acceptable.
    BehaviorSubject<ParseChange<P>> updates = updatesPerResource.get(name);
    if(updates == null) {
        updates = BehaviorSubject.create();
        updatesPerResource.put(name, updates);
        try {
            logger.trace("Parsing for {}", resource);
            final P result = syntaxService.parse(unit);
            updates.onNext(ParseChange.update(result));
        } catch(ParseException e) {
            final String message = String.format("Parsing for %s failed", name);
            logger.error(message, e);
            updates.onNext(ParseChange.<P>error(e));
        }
    }
    return updates;
}
 

开发者ID:metaborg,
项目名称:spoofax,
代码行数:24,
代码来源:ParseResultProcessor.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)