-
Notifications
You must be signed in to change notification settings - Fork 8
/
wrapper_oneshot.go
123 lines (99 loc) · 3.27 KB
/
wrapper_oneshot.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
package mono
import (
"context"
"sync"
"time"
"github.com/jjeffcaii/reactor-go"
"github.com/jjeffcaii/reactor-go/scheduler"
)
var _oneshotWrapperPool = sync.Pool{
New: func() interface{} {
return new(oneshotWrapper)
},
}
type oneshotWrapper struct {
reactor.RawPublisher
}
func borrowOneshotWrapper(origin reactor.RawPublisher) *oneshotWrapper {
wrapper := _oneshotWrapperPool.Get().(*oneshotWrapper)
wrapper.RawPublisher = origin
return wrapper
}
func returnOneshotWrapper(o *oneshotWrapper) (raw reactor.RawPublisher) {
raw, o.RawPublisher = o.RawPublisher, nil
_oneshotWrapperPool.Put(o)
return
}
func (o *oneshotWrapper) Subscribe(ctx context.Context, options ...reactor.SubscriberOption) {
returnOneshotWrapper(o).SubscribeWith(ctx, reactor.NewSubscriber(options...))
}
func (o *oneshotWrapper) Filter(predicate reactor.Predicate) Mono {
o.RawPublisher = newMonoFilter(o.RawPublisher, predicate)
return o
}
func (o *oneshotWrapper) Map(transformer reactor.Transformer) Mono {
o.RawPublisher = newMonoMap(o.RawPublisher, transformer)
return o
}
func (o *oneshotWrapper) FlatMap(mapper FlatMapper) Mono {
o.RawPublisher = newMonoFlatMap(o.RawPublisher, mapper)
return o
}
func (o *oneshotWrapper) SubscribeOn(scheduler scheduler.Scheduler) Mono {
o.RawPublisher = newMonoScheduleOn(o.RawPublisher, scheduler)
return o
}
func (o *oneshotWrapper) Block(ctx context.Context) (Any, error) {
return block(ctx, returnOneshotWrapper(o))
}
func (o *oneshotWrapper) DoOnNext(next reactor.FnOnNext) Mono {
o.RawPublisher = newMonoPeek(o.RawPublisher, peekNext(next))
return o
}
func (o *oneshotWrapper) DoOnComplete(complete reactor.FnOnComplete) Mono {
o.RawPublisher = newMonoPeek(o.RawPublisher, peekComplete(complete))
return o
}
func (o *oneshotWrapper) DoOnSubscribe(subscribe reactor.FnOnSubscribe) Mono {
o.RawPublisher = newMonoPeek(o.RawPublisher, peekSubscribe(subscribe))
return o
}
func (o *oneshotWrapper) DoOnError(onError reactor.FnOnError) Mono {
o.RawPublisher = newMonoPeek(o.RawPublisher, peekError(onError))
return o
}
func (o *oneshotWrapper) DoOnCancel(cancel reactor.FnOnCancel) Mono {
o.RawPublisher = newMonoPeek(o.RawPublisher, peekCancel(cancel))
return o
}
func (o *oneshotWrapper) DoFinally(finally reactor.FnOnFinally) Mono {
o.RawPublisher = newMonoDoFinally(o.RawPublisher, finally)
return o
}
func (o *oneshotWrapper) SwitchValueIfError(v Any) Mono {
o.RawPublisher = newMonoDoCreateIfError(o.RawPublisher, v)
return o
}
func (o *oneshotWrapper) DoOnDiscard(discard reactor.FnOnDiscard) Mono {
o.RawPublisher = newMonoContext(o.RawPublisher, withContextDiscard(discard))
return o
}
func (o *oneshotWrapper) SwitchIfEmpty(alternative Mono) Mono {
o.RawPublisher = newMonoSwitchIfEmpty(o.RawPublisher, alternative)
return o
}
func (o *oneshotWrapper) SwitchIfError(alternative func(error) Mono) Mono {
o.RawPublisher = newMonoSwitchIfError(o.RawPublisher, alternative)
return o
}
func (o *oneshotWrapper) DelayElement(delay time.Duration) Mono {
o.RawPublisher = newMonoDelayElement(o.RawPublisher, delay, scheduler.Parallel())
return o
}
func (o *oneshotWrapper) Timeout(timeout time.Duration) Mono {
o.RawPublisher = newMonoTimeout(o.RawPublisher, timeout)
return o
}
func (o *oneshotWrapper) Raw() reactor.RawPublisher {
return o.RawPublisher
}