-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandling.go
54 lines (43 loc) · 907 Bytes
/
handling.go
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
49
50
51
52
53
54
package decs
import "sync/atomic"
func (cbus *CommandBus) handleCommands() {
for {
select {
case cmd := <-cbus.queue.q:
cbus.handleCommand(cmd)
atomic.AddInt32(&cbus.incomingCount, -1)
}
}
}
func (cbus *CommandBus) handleCommand(cmd *command) {
if cmd.Undo {
cbus.undo(1)
return
}
// ensure idempotence
if cbus.versionTracker.alreadyHandled(cmd) {
return
}
// custom filtering
if cmd.bus.filterOut(cmd) {
return
}
if cbus.cachingSuspended || cmd.Oneshot {
cbus.doEventually(cmd, false)
return
}
if cbus.isInFlow(cmd.Name_) {
cbus.doEventually(cmd, true)
cbus.flows[cmd.Name_] = append(cbus.flows[cmd.Name_], cmd)
return
}
// record command if necessary
if cbus.Recorder.IsRecording() {
cbus.Recorder.append(cmd)
}
if cbus.defs[cmd.Name_].Flowing() {
cbus.EnterFlow(cmd.Name_)
defer cbus.ExitFlow(cmd.Name_)
}
cbus.doEventually(cmd, true)
}