-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobservers.go
130 lines (112 loc) · 2.34 KB
/
observers.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package goreact
import (
uuid "github.com/satori/go.uuid"
)
type NextEvent func(v interface{}) Disposable
type FailedEvent func(err error) Disposable
type CompletedEvent func(completed bool) Disposable
type TerminatedEvent func() Disposable
type NextEventWithMeta func(v interface{}, metas ...interface{}) Disposable
type FailedEventWithMeta func(err error, metas ...interface{}) Disposable
type CompletedEventWithMeta func(completed bool, metas ...interface{}) Disposable
type Observer interface {
Injector
GetId() uuid.UUID
CleanUp()
SendTerminated()
}
type Observe struct {
id uuid.UUID
next NextEvent
failed FailedEvent
completed CompletedEvent
terminated TerminatedEvent
timeline BagDisposer
}
func (o Observe) GetId() uuid.UUID {
return o.id
}
func (o Observe) CleanUp() {
o.timeline.Dispose()
}
func (o Observe) SendFailed(err error) {
if o.failed != nil {
disp := o.failed(err)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o Observe) SendNext(value interface{}) {
if o.next != nil {
disp := o.next(value)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o Observe) SendCompleted() {
if o.completed != nil {
disp := o.completed(true)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o Observe) SendTerminated() {
if o.terminated != nil {
disp := o.terminated()
if disp != nil {
o.timeline.Add(disp)
}
}
// o.CleanUp()
}
type MetaObserve struct {
id uuid.UUID
next NextEventWithMeta
failed FailedEventWithMeta
completed CompletedEventWithMeta
terminated TerminatedEvent
timeline BagDisposer
metas []interface{}
}
func (o MetaObserve) GetId() uuid.UUID {
return o.id
}
func (o MetaObserve) CleanUp() {
o.timeline.Dispose()
}
func (o MetaObserve) SendFailed(err error) {
if o.failed != nil {
disp := o.failed(err, o.metas...)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o MetaObserve) SendNext(value interface{}) {
if o.next != nil {
disp := o.next(value, o.metas...)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o MetaObserve) SendCompleted() {
if o.completed != nil {
disp := o.completed(true, o.metas...)
if disp != nil {
o.timeline.Add(disp)
}
}
}
func (o MetaObserve) SendTerminated() {
if o.terminated != nil {
disp := o.terminated()
if disp != nil {
o.timeline.Add(disp)
}
}
// o.CleanUp()
}