renderAndWait method
Future<RenderJobView>
renderAndWait(
- ApiRenderRequest request, {
- void onUpdate(
- RenderJobView job
- Duration pollInterval = const Duration(seconds: 1),
- Duration timeout = const Duration(minutes: 10),
- Future<
void> wait() = _realWait,
Creates a render and polls until it succeeds or fails, calling onUpdate
with each status. Throws ApiClientException on failure or when timeout
elapses first.
Implementation
Future<RenderJobView> renderAndWait(
ApiRenderRequest request, {
void Function(RenderJobView job)? onUpdate,
Duration pollInterval = const Duration(seconds: 1),
Duration timeout = const Duration(minutes: 10),
Future<void> Function(Duration) wait = _realWait,
}) async {
final created = await createRender(request);
onUpdate?.call(created);
var waited = Duration.zero;
var latest = created;
while (latest.isPending) {
if (waited >= timeout) {
throw const ApiClientException('Timed out waiting for the render to finish');
}
await wait(pollInterval);
waited += pollInterval;
latest = await getJob(created.id);
onUpdate?.call(latest);
}
if (latest.isFailed) {
throw ApiClientException(latest.error ?? 'Render failed');
}
return latest;
}