use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class ReverseTest method limitList.
@Test
public void limitList() throws InterruptedException {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 1000; i++) list.add(i);
assertThat(new LazyReact().fromIterable(list).limit(100).peek(System.out::println).count(), equalTo(100L));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqAutoOptimizeTest method longRunForEach.
@Test
public void longRunForEach() {
new LazyReact().autoOptimizeOn().range(0, 1_000_000).map(i -> i + 2).map(i -> Thread.currentThread().getId()).forEach(a -> {
});
System.out.println("Finished!");
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqAutoOptimizeTest method longRun.
@Test
public void longRun() {
AtomicInteger count = new AtomicInteger(0);
new LazyReact().autoOptimizeOn().range(0, 1_000_000).map(i -> i + 2).map(i -> Thread.currentThread().getId()).peek(i -> count.incrementAndGet()).runOnCurrent();
System.out.println("Finished! " + count.get());
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqObjectPoolingTest method shouldZipInfiniteWithFiniteSeq.
@Test
public void shouldZipInfiniteWithFiniteSeq() throws Exception {
ThreadPools.setUseCommon(false);
// <-- MEMORY LEAK!- no auto-closing yet, so writes infinetely to it's async queue
final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
final ReactiveSeq<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100).limit(5);
final ReactiveSeq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p);
assertThat(zipped.limit(5).join(), equalTo(of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join()));
ThreadPools.setUseCommon(true);
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqObjectPoolingTest method zipFastSlow.
@Test
public void zipFastSlow() {
Queue q = new Queue();
LazyReact.parallelBuilder().generate(() -> sleep(100)).then(it -> q.add("100")).runThread(new Thread());
new LazyReact().of(1, 2, 3, 4, 5, 6).zip(q.stream()).peek(it -> System.out.println(it)).collect(Collectors.toList());
}
Aggregations