io.reactivex.Flowable.just()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(535)

本文整理了Java中io.reactivex.Flowable.just()方法的一些代码示例,展示了Flowable.just()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.just()方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:just

Flowable.just介绍

[英]Returns a Flowable that signals the given (constant reference) item and then completes.

Note that the item is taken and re-emitted as is and not computed by any means by just. Use #fromCallable(Callable)to generate a single item on demand (when Subscribers subscribe to it).

See the multi-parameter overloads of just to emit more than one (constant reference) items one after the other. Use #fromArray(Object...) to emit an arbitrary number of items that are known upfront.

To emit the items of an Iterable sequence (such as a java.util.List), use #fromIterable(Iterable). Backpressure: The operator honors backpressure from downstream. Scheduler: just does not operate by default on a particular Scheduler.
[中]返回给给定(常量引用)项发信号然后完成的可流动项。
请注意,项目是按原样获取和重新发射的,而不是通过任何方式计算的。使用#fromCallable(Callable)按需生成单个项目(当订阅者订阅时)。
请参见的多参数重载,以便逐个发出多个(常量引用)项。使用#fromArray(对象…)发出预先已知的任意数量的项。
要发出Iterable序列的项(例如java.util.List),请使用#fromIterable(Iterable)。背压:操作员接受来自下游的背压。调度程序:只是默认情况下不在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Flowable<Integer> apply(Integer v) {
    return Flowable.just(v);
  }
});

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Flowable<Integer> apply(Object v) throws Exception {
    return Flowable.just(1);
  }
}, 16));

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatObservableDelayErrorTillEnd() {
  Flowable.concatDelayError(
      Flowable.just(Flowable.just(1), Flowable.just(2),
      Flowable.just(3).concatWith(Flowable.<Integer>error(new TestException())),
      Flowable.just(4)), 2, true)
  .test()
  .assertFailure(TestException.class, 1, 2, 3, 4);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void concatIterableDelayErrorWithError() {
  Flowable.concatDelayError(
      Arrays.asList(Flowable.just(1), Flowable.just(2),
      Flowable.just(3).concatWith(Flowable.<Integer>error(new TestException())),
      Flowable.just(4)))
  .test()
  .assertFailure(TestException.class, 1, 2, 3, 4);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Integer> apply(Flowable<Object> f) throws Exception {
    return f.concatMapDelayError(Functions.justFunction(Flowable.just(2)));
  }
});

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatDelayErrorFlowable() {
  TestSubscriber<Integer> ts = TestSubscriber.create();
  Flowable.concatDelayError(
      Flowable.just(Flowable.just(1), Flowable.just(2)))
  .subscribe(ts);
  ts.assertValues(1, 2);
  ts.assertNoErrors();
  ts.assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSkipAndCountGaplessBuffers() {
  Flowable<String> source = Flowable.just("one", "two", "three", "four", "five");
  Flowable<List<String>> buffered = source.buffer(3, 3);
  buffered.subscribe(subscriber);
  InOrder inOrder = Mockito.inOrder(subscriber);
  inOrder.verify(subscriber, Mockito.times(1)).onNext(list("one", "two", "three"));
  inOrder.verify(subscriber, Mockito.times(1)).onNext(list("four", "five"));
  inOrder.verify(subscriber, Mockito.never()).onNext(Mockito.<String>anyList());
  inOrder.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class));
  inOrder.verify(subscriber, Mockito.times(1)).onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatMapDelayErrorWithError() {
  Flowable.just(Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())), Flowable.just(2))
  .concatMapDelayError(Functions.<Flowable<Integer>>identity())
  .test()
  .assertFailure(TestException.class, 1, 2);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void skipSingleResult() {
  Flowable.just(1)
  .buffer(2, 3)
  .test()
  .assertResult(Arrays.asList(1));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testUnsubscribeSource() throws Exception {
  Action unsubscribe = mock(Action.class);
  Flowable<Integer> f = Flowable.just(1).doOnCancel(unsubscribe).cache();
  f.subscribe();
  f.subscribe();
  f.subscribe();
  verify(unsubscribe, never()).run();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void Flowable() {
  Flowable<Integer> source = Flowable.just(1);
  TestSubscriber<Integer> ts = TestSubscriber.create();
  Flowable.concatEager(Flowable.just(source, source, source)).subscribe(ts);
  ts.assertValues(1, 1, 1);
  ts.assertNoErrors();
  ts.assertComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstreamFlowable() {
  Flowable<Integer> source = Flowable.just(1).isEmpty()
    .flatMapPublisher(new Function<Boolean, Publisher<Integer>>() {
      @Override
      public Publisher<Integer> apply(Boolean t1) {
        return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS);
      }
    });
  assertEquals((Object)2, source.blockingFirst());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatMapJustSourceDelayError() {
  Flowable.just(0).hide()
  .concatMapDelayError(new Function<Object, Flowable<Integer>>() {
    @Override
    public Flowable<Integer> apply(Object v) throws Exception {
      return Flowable.just(1);
    }
  }, 16, false)
  .test()
  .assertResult(1);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatMapEmptyDelayError() {
  Flowable.just(1).hide()
  .concatMapDelayError(Functions.justFunction(Flowable.empty()))
  .test()
  .assertResult();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void fusedCrash() {
  Flowable.range(1, 2)
  .map(new Function<Integer, Object>() {
    @Override
    public Object apply(Integer v) throws Exception { throw new TestException(); }
  })
  .concatMap(Functions.justFunction(Flowable.just(1)))
  .test()
  .assertFailure(TestException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void callableCrashDelayError() {
  Flowable.just(1).hide()
  .concatMapDelayError(Functions.justFunction(Flowable.fromCallable(new Callable<Object>() {
    @Override
    public Object call() throws Exception {
      throw new TestException();
    }
  })))
  .test()
  .assertFailure(TestException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void error() {
  Flowable.error(new TestException())
  .concatMapDelayError(Functions.justFunction(Flowable.just(2)), 16, false)
  .test()
  .assertFailure(TestException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void testInnerError() {
  Flowable.concatArrayEager(Flowable.just(1), Flowable.error(new TestException())).subscribe(ts);
  ts.assertValue(1);
  ts.assertError(TestException.class);
  ts.assertNotComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void concatMapInnerError() {
  Flowable.just(1).hide()
  .concatMap(Functions.justFunction(Flowable.error(new TestException())))
  .test()
  .assertFailure(TestException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void scalarAndEmptyBackpressured() {
  TestSubscriber<Integer> ts = TestSubscriber.create(0);
  Flowable.just(1).concatWith(Flowable.<Integer>empty()).subscribe(ts);
  ts.assertNoValues();
  ts.request(5);
  ts.assertValue(1);
  ts.assertComplete();
  ts.assertNoErrors();
}

相关文章

Flowable类方法