forked from digitalocean/firebolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
48 lines (42 loc) · 1.23 KB
/
event.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
package firebolt
import "time"
// Event is the struct passed through the node graph.
type Event struct {
Payload interface{} `json:"payload"`
Created time.Time `json:"created"`
Recovery bool `json:"recovery"`
}
// AsyncEvent is a version of Event for nodes that support asynchronous processing.
type AsyncEvent struct {
*Event
ReturnError func(error)
ReturnEvent func(*AsyncEvent)
ReturnFiltered func()
}
// NewAsyncEvent creates a version of the passed Event suitable for asynchronous processing.
func NewAsyncEvent(event *Event, errFunc func(error), eventFunc func(*AsyncEvent), filterFunc func()) *AsyncEvent {
return &AsyncEvent{
Event: event,
ReturnError: errFunc,
ReturnEvent: eventFunc,
ReturnFiltered: filterFunc,
}
}
// WithPayload returns a clone of this event with the payload replaced.
func (e *Event) WithPayload(payload interface{}) *Event {
return &Event{
Payload: payload,
Created: e.Created,
Recovery: e.Recovery,
}
}
// WithPayload returns a clone of this event with the payload replaced.
func (ae *AsyncEvent) WithPayload(payload interface{}) *AsyncEvent {
return &AsyncEvent{
Event: &Event{
Payload: payload,
Created: ae.Created,
Recovery: ae.Recovery,
},
}
}