Interface
ResultStream is used as a sink for returning an unbounded
sequence of values from a service method.
The interface is used as a parameter in implementation of a method
corresponding to a service interface method returning
ResultStreamBuilder.
e.g.
public interface MyService {
ResultStreamBuilder<String> results();
}
@io.baratine.core.Service("public://pod/service")
public class MyServiceImpl implements MyService {
public void results(ResultStream<String> stream) {
stream.accept("Hello");
stream.accept("World");
stream.complete();
}
@Override
public void ResultStreamBuilder<String> results() {
throw new UnsupportedOperationException();
}
}
Sending a new value can be accomplished with passing it to method
accept.
After the last value is submitted the service needs to call method
completeto signal the
ResultStream that last value has been submitted}
The client obtaining the results from the corresponding
ResultStreamBuildermay choose to cancel further results. When
ResultStream is cancelled
its cancelled state is set to true and method
onCancell(CancelHandle)is called. Method
isCancelled() can be used to test if the stream
was cancelled to avoid sending values to a cancelled stream.