forked from nyaruka/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.go
38 lines (29 loc) · 977 Bytes
/
msg.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
package waits
import (
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
)
const TypeMsg string = "msg"
// MsgWait is a wait which waits for an incoming message (i.e. a msg_received event)
type MsgWait struct {
baseTimeoutWait
}
// NewMsgWait creates a new message wait
func NewMsgWait(timeout *int) *MsgWait {
return &MsgWait{baseTimeoutWait{Timeout_: timeout}}
}
// Type returns the type of this wait
func (w *MsgWait) Type() string { return TypeMsg }
// Begin beings waiting at this wait
func (w *MsgWait) Begin(run flows.FlowRun, step flows.Step) {
w.baseTimeoutWait.Begin(run)
run.ApplyEvent(step, nil, events.NewMsgWait(w.TimeoutOn_))
}
// CanResume returns true if a message event has been received
func (w *MsgWait) CanResume(callerEvents []flows.Event) bool {
if containsEventOfType(callerEvents, events.TypeMsgReceived) {
return true
}
return w.baseTimeoutWait.CanResume(callerEvents)
}
var _ flows.Wait = (*MsgWait)(nil)