Remove worker callbacks when Done is received

This commit is contained in:
Drew DeVault 2019-06-02 13:20:02 -04:00
parent 7d1770754f
commit a81467dda9
2 changed files with 13 additions and 5 deletions

View File

@ -34,7 +34,7 @@ func (m Message) getId() int64 {
return m.id return m.id
} }
func (m Message) setId(id int64) { func (m *Message) setId(id int64) {
m.id = id m.id = id
} }

View File

@ -72,13 +72,17 @@ func (worker *Worker) PostMessage(msg WorkerMessage,
func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage { func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage {
if resp := msg.InResponseTo(); resp != nil { if resp := msg.InResponseTo(); resp != nil {
worker.Logger.Printf("(ui)<= %T:%T\n", msg, resp) worker.Logger.Printf("(ui)<= %T(%d):%T(%d)\n",
msg, msg.getId(), resp, resp.getId())
} else { } else {
worker.Logger.Printf("(ui)<= %T\n", msg) worker.Logger.Printf("(ui)<= %T(%d)\n", msg, msg.getId())
} }
if inResponseTo := msg.InResponseTo(); inResponseTo != nil { if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
if f, ok := worker.actionCallbacks[inResponseTo.getId()]; ok { if f, ok := worker.actionCallbacks[inResponseTo.getId()]; ok {
f(msg) f(msg)
if _, ok := msg.(*Done); ok {
delete(worker.actionCallbacks, inResponseTo.getId())
}
} }
} }
return msg return msg
@ -86,13 +90,17 @@ func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage {
func (worker *Worker) ProcessAction(msg WorkerMessage) WorkerMessage { func (worker *Worker) ProcessAction(msg WorkerMessage) WorkerMessage {
if resp := msg.InResponseTo(); resp != nil { if resp := msg.InResponseTo(); resp != nil {
worker.Logger.Printf("<-(ui) %T:%T\n", msg, resp) worker.Logger.Printf("<-(ui) %T(%d):%T(%d)\n",
msg, msg.getId(), resp, resp.getId())
} else { } else {
worker.Logger.Printf("<-(ui) %T\n", msg) worker.Logger.Printf("<-(ui) %T(%d)\n", msg, msg.getId())
} }
if inResponseTo := msg.InResponseTo(); inResponseTo != nil { if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
if f, ok := worker.messageCallbacks[inResponseTo.getId()]; ok { if f, ok := worker.messageCallbacks[inResponseTo.getId()]; ok {
f(msg) f(msg)
if _, ok := msg.(*Done); ok {
delete(worker.messageCallbacks, inResponseTo.getId())
}
} }
} }
return msg return msg