1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::App;
use kanban_domain::KanbanResult;
impl App {
/// Execute a single command and queue a flush.
/// For multiple commands, prefer `execute_commands_batch` to produce only one flush signal.
pub fn execute_command(
&mut self,
command: kanban_domain::commands::Command,
) -> KanbanResult<()> {
self.execute_commands_batch(vec![command])
}
/// Execute multiple commands as a batch, producing a single flush signal.
pub fn execute_commands_batch(
&mut self,
commands: Vec<kanban_domain::commands::Command>,
) -> KanbanResult<()> {
self.ctx.execute_commands_batch(commands)?;
Ok(())
}
/// Like `execute_commands_batch`, but the batch is built inside the
/// transaction so anything the builder writes (e.g. allocating a card
/// number) rolls back with it. See `KanbanContext::execute_with`.
pub fn execute_with(
&mut self,
build: impl FnOnce(
&dyn kanban_domain::DataStore,
) -> KanbanResult<Vec<kanban_domain::commands::Command>>,
) -> KanbanResult<()> {
self.execute_with_extra(kanban_domain::EntityIds::default(), build)
}
/// Like [`execute_with`](Self::execute_with), but `extra` is unioned
/// into the invalidation the batch derives. See
/// `KanbanContext::execute_with_extra`.
pub fn execute_with_extra(
&mut self,
extra: kanban_domain::EntityIds,
build: impl FnOnce(
&dyn kanban_domain::DataStore,
) -> KanbanResult<Vec<kanban_domain::commands::Command>>,
) -> KanbanResult<()> {
self.ctx.execute_with_extra(extra, build)?;
Ok(())
}
}