googleapis/google-cloud-php

Expose async (promise-returning) methods in ImageAnnotatorClient

mikethea1 opened this issue · 0 comments

Thanks for stopping by to let us know something could be better!

Is your feature request related to a problem? Please describe.
I'm using the ImageAnnotatorClient to OCR some pages from a document. Because the API only accepts 5 pages at a time (and sometimes fails with a full 5, doing this serially takes many seconds to finish; sometimes the request times out just processing a modest number of pages.

Describe the solution you'd like

Under the hood, the annotator client is actually calling ->wait() on an async promise before returning. I'd like for an API like batchAnnotateImagesAsync() which just returned the promise directly. This would allow me to process in parallel:

$promises = array_map(fn($r) => $imageAnnotator->batchAnnotateImagesAsync($r), $requests);
foreach ($promises as $promise) {
    $result = $promise->wait();
    // do something with $result
}

Describe alternatives you've considered
The current client DOES have a asyncBatchAnnotateImages() function, but this synchronously sets up an offline operation. I'm still doing online operations; I'd just like to parallelize for speed.