Skip to content

Type Interfaces : ReactiveTask

johnmcclean-aol edited this page Nov 23, 2016 · 1 revision

The ReactiveTask interface

A ReactiveTask represents a currently executing task that callers can control in some manner. It extends Reactive Streams Subscription.

ReactiveTask contains the following methods

  • block - Block until the currently active reactive task completes
  • cancel - cancel the currently active task
  • isCurrentTaskComplete - check if task is complete
  • isStreamComplete - check if full Stream is complete
  • request - request n elements
  • requestAll - request all elements
  • requestAllAsync - request all elements asynchronously
  • requestAsync - request n elements asynchronously

Example

ReactiveTask s = ReactiveSeq.of(1,2,3)
		            .futureOperations(exec)
			    .forEachX( 2, System.out::println);
		
System.out.println("first batch");
s.request(1);
s.block();


List<Integer> list = new ArrayList<>();
ReactiveTask s = ReactiveSeq.of(1,2,3)
			    .futureOperations(exec)
			    .forEachX( 2,  i->list.add(i));
s.block();

assertThat(list,hasItems(1,2));
assertThat(list.size(),equalTo(2));

s.requestAllAsync();
  
//do work

//block to test
s.block();		
assertThat(list,hasItems(1,2,3));
assertThat(list.size(),equalTo(3));

Used in

ReactiveSeq, LazyFutureStream via ReactiveStreamsTerminalFutureOperations

futureOperations(exec).forEachXXX(   );
Clone this wiki locally