Files
flutter_lua_runtime/lib/runtime/commands/command_composite.dart
2026-06-07 22:53:58 +08:00

53 lines
1.6 KiB
Dart

part of 'command_executor.dart';
extension _CommandExecutorComposite on CommandExecutor {
Future<_CommandResult> _sequence(
RuntimeCommand command,
_CommandContext context,
RuntimeCommandHandle? handle,
) async {
final commands = _commandsFromPayload(command);
final childContext = _childContextFor(command, context);
for (final child in commands) {
if (_disposed ||
(handle?.isCancelled ?? false) ||
!_scopeIsAlive(childContext.scope)) {
return _CommandResult.cancelled;
}
final result = await _execute(child, childContext);
if (result == _CommandResult.cancelled) {
return _CommandResult.cancelled;
}
}
if (_disposed ||
(handle?.isCancelled ?? false) ||
!_scopeIsAlive(childContext.scope)) {
return _CommandResult.cancelled;
}
_emitCommandCompletion(command, childContext);
return _CommandResult.completed;
}
Future<_CommandResult> _parallel(
RuntimeCommand command,
_CommandContext context,
RuntimeCommandHandle? handle,
) async {
final commands = _commandsFromPayload(command);
final childContext = _childContextFor(command, context);
final results = await Future.wait(
commands.map((child) => _execute(child, childContext)),
);
if (_disposed ||
(handle?.isCancelled ?? false) ||
!_scopeIsAlive(childContext.scope) ||
results.contains(_CommandResult.cancelled)) {
return _CommandResult.cancelled;
}
_emitCommandCompletion(command, childContext);
return _CommandResult.completed;
}
}