Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public void handleRequest(ScrapeReq input) throws Exception {
FlowFuture<ScrapeResp> scrapes = currentFlow().invokeFunction("./scraper", input, ScrapeResp.class);
scrapes.thenCompose(resp -> {
List<ScrapeResp.ScrapeResult> results = resp.result;
List<FlowFuture<?>> pendingTasks = results
.map(scrapeResult -> {"starting image detection on {}", scrapeResult.image_url);
String id =;
return currentFlow()
.invokeFunction("./detect-plates", new DetectPlateReq(scrapeResult.image_url, "us"), DetectPlateResp.class)
.thenCompose((plateResp) -> {
if (!plateResp.got_plate) {"No plates found in {}", scrapeResult.image_url);
// bug
return currentFlow().completedValue(null);
}"Got plate {} in {}", plateResp.plate, scrapeResult.image_url);
return currentFlow()
.invokeFunction("./draw", new DrawReq(id, scrapeResult.image_url, plateResp.rectangles,"300x300"), DrawResp.class)
.thenCompose((drawResp) -> {"Got draw response {} ", drawResp.image_url);
return currentFlow().allOf(
currentFlow().invokeFunction("./alert", new AlertReq(plateResp.plate, drawResp.image_url)),
"Found plate: " + plateResp.plate,
"Have you seen this car?"));
return currentFlow()
.allOf(pendingTasks.toArray(new FlowFuture[pendingTasks.size()]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.