-
Notifications
You must be signed in to change notification settings - Fork 8
/
reactor.go
60 lines (51 loc) · 1.09 KB
/
reactor.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
package reactor
import "context"
// Item is type of element.
type Item struct {
V Any
E error
}
// SignalType is type of terminal signal.
type SignalType int8
func (s SignalType) String() string {
switch s {
case SignalTypeComplete:
return "COMPLETE"
case SignalTypeDefault:
return "DEFAULT"
case SignalTypeCancel:
return "CANCEL"
case SignalTypeError:
return "ERROR"
default:
return "UNKNOWN"
}
}
const (
SignalTypeDefault SignalType = iota
SignalTypeComplete
SignalTypeCancel
SignalTypeError
)
// Any is an alias of interface{} which means a value of any type.
type Any = interface{}
type (
Predicate func(Any) bool
Transformer func(Any) (Any, error)
)
// A group of action functions.
type (
FnOnComplete = func()
FnOnNext = func(v Any) error
FnOnCancel = func()
FnOnSubscribe = func(ctx context.Context, su Subscription)
FnOnRequest = func(n int)
FnOnError = func(e error)
FnOnFinally = func(s SignalType)
FnOnDiscard = func(v Any)
)
// Disposable is a disposable resource.
type Disposable interface {
// Dispose dispose current resource.
Dispose()
}