Initial flame_lua_runtime package
This commit is contained in:
52
lib/runtime/commands/command_composite.dart
Normal file
52
lib/runtime/commands/command_composite.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user