How to execute multiple dependent blocking calls

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to execute multiple dependent blocking calls

jlorenzen
The following is some code I have in a thread-based app that I'm trying to rewrite as a ratpack application. I've racked my brain trying to figure out how to port this code over using ratpack's Promises but I haven't been able to figure it out.

final PipelineHistory firstPagePipelineHistory = pipelineHistoryExecutor.getHistory(projectName, 0);
final List pipelines = new ArrayList<>();
pipelines.addAll(firstPagePipelineHistory.getPipelines());
final int pageSize = firstPagePipelineHistory.getPageSize();
final int neededPageSize = getNeededPageSize(pageSize)
for (int i = 1; i < neededPageSize; i++) {
    final PipelineHistory nextPagePipelineHistory = pipelineHistoryExecutor.getHistory(projectName, i * pageSize);
    pipelines.addAll(nextPagePipelineHistory.getPipelines());
}

return pipelines;


The method pipelineHistoryExecutor.getHistory is performing IO. As you can see, I need a value (ie pageSize) from the first request in order to determine if I need to continue making other IO requests. The end result is I need to combine the results from each request into a single object.

I'm wondering if I can accomplish this simply with ratpack's Promises or if I need to use something like RxJava (in which case I wouldn't even know where to begin)?

Thanks,
James Lorenzen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to execute multiple dependent blocking calls

jlorenzen
For those interested, we had a conversation about my question in the ratpack slack: https://ratpack.slack.com/archives/C07KYDYET/p1495719252795784
Loading...