sequence static method
A command that runs commands in sequence.
Each command completes before the next starts. Messages are collected and returned together after all commands complete.
return (newModel, Cmd.sequence([
initializeDatabase(),
loadConfiguration(),
startServer(),
]));
Implementation
static Cmd sequence(List<Cmd> commands) {
if (commands.isEmpty) return none();
if (commands.length == 1) return commands.first;
return Cmd(() async {
final messages = <Msg>[];
for (final cmd in commands) {
final msg = await cmd.execute();
if (msg != null) messages.add(msg);
}
if (messages.isEmpty) return null;
if (messages.length == 1) return messages.first;
return BatchMsg(messages);
});
}