waitForExportProcessing method
Implementation
Future<Export> waitForExportProcessing(String projectId) async {
Export? lastUpdateExport;
final periodicStream = Stream<void>.periodic(const Duration(seconds: 15));
final eventStreamSubscription =
_projectService.getProjectUpdateEvents(projectId);
final combinedEventStream = StreamGroup.mergeBroadcast<void>(
[
periodicStream,
eventStreamSubscription,
],
).asBroadcastStream();
do {
final export = await getLatestExportByProject(projectId);
// print('Wait: ${export.id} -> ${export.status}:${export.progress}');
if (export.status == Export_Status.pending ||
export.status == Export_Status.processing) {
lastUpdateExport = export;
await combinedEventStream.first;
} else {
lastUpdateExport = export;
}
} while (lastUpdateExport.status == Export_Status.pending ||
lastUpdateExport.status == Export_Status.processing);
// print(
// 'Wait finish: ${lastUpdateExport.id} -> ${lastUpdateExport.status}:${lastUpdateExport.error}',
// );
return lastUpdateExport;
}