예제 #1
0
  @Test
  public void fizzTest() throws Throwable {
    int numOfItems = 1024;
    int batchSize = 8;
    final Timer timer = new Timer();
    AtomicLong globalCounter = new AtomicLong();
    CountDownLatch latch = new CountDownLatch(1);

    Control c =
        Streams.createWith(
                (demand, subscriber) -> {
                  System.out.println("demand is " + demand);
                  if (!subscriber.isCancelled()) {
                    for (int i = 0; i < demand; i++) {
                      long curr = globalCounter.incrementAndGet();
                      if (curr % 5 == 0 && curr % 3 == 0) subscriber.onNext("FizBuz \r\n");
                      else if (curr % 3 == 0) subscriber.onNext("Fiz ");
                      else if (curr % 5 == 0) subscriber.onNext("Buz ");
                      else subscriber.onNext(String.valueOf(curr) + " ");

                      if (globalCounter.get() > numOfItems) {
                        subscriber.onComplete();
                        return;
                      }
                    }
                  }
                })
            .flatMap(
                (s) ->
                    Streams.withOverflowSupport(
                        (sub) ->
                            timer.schedule(
                                new TimerTask() {
                                  @Override
                                  public void run() {
                                    sub.onNext(s);
                                    sub.onComplete();
                                  }
                                },
                                10)))
            .capacity(batchSize)
            .log()
            //                .observe(System.out::print)
            .consume(numOfItems);

    while (c.isPublishing()) ;
  }
예제 #2
0
 @Override
 public StreamUtils.StreamVisitor debug() {
   return controls.debug();
 }
예제 #3
0
 @Override
 public void requestMore(long n) {
   controls.requestMore(n);
 }
예제 #4
0
 @Override
 public boolean isPublishing() {
   return controls.isPublishing();
 }
예제 #5
0
 @Override
 public void cancel() {
   controls.cancel();
 }
예제 #6
0
 @Override
 public void start() {
   controls.start();
 }