generateAll method
Future<void>
generateAll(
- Iterable<
GenerativeSource> sources, { - void onProgress(
- GenerativeProgress progress
Produces every source in sources (cache hit or generate) so that
mediaFor, audioFor, and metaFor can answer synchronously afterwards.
Runs before the first frame and is idempotent: producing the same source
(by GenerativeSource.cacheKey) twice does the work once. Reports coarse
progress through onProgress. Throws a FluvieGenerativeException when a
source cannot be produced (provider error, offline cache miss, or budget).
Implementation
@override
Future<void> generateAll(
Iterable<GenerativeSource> sources, {
void Function(GenerativeProgress progress)? onProgress,
}) async {
final list = sources.toList();
var generated = 0;
for (var i = 0; i < list.length; i++) {
final source = list[i];
if (_meta.containsKey(source)) continue;
final key = source.cacheKey;
if (_cache.has(source.providerId, key)) {
_loadFromCache(source, key);
_report(onProgress, i, list.length, source, 'cached');
continue;
}
if (_config.offline) {
throw FluvieGenerativeException(
'Offline: no cached asset for $source. Pre-warm the cache (run once '
'online and commit .fluvie/generative) or unset FLUVIE_GENERATIVE_OFFLINE.',
);
}
final budget = _config.maxGenerations;
if (budget != null && generated >= budget) {
throw FluvieGenerativeException(
'Generation budget ($budget) exceeded while resolving $source.',
);
}
_report(onProgress, i, list.length, source, 'generating');
await _storeProduced(source, key, await _runGenerate(source));
generated++;
_report(onProgress, i, list.length, source, 'done');
}
}