26
26
// executors.ChunkExecutor options
27
27
chunkSize int
28
28
flushInterval time.Duration
29
+
30
+ // enableSyncPush is used to enable sync push
31
+ enableSyncPush bool
29
32
}
30
33
)
31
34
@@ -46,6 +49,16 @@ func NewPusher(addrs []string, topic string, opts ...PushOption) *Pusher {
46
49
// apply kafka.Writer options
47
50
producer .AllowAutoTopicCreation = options .allowAutoTopicCreation
48
51
52
+ pusher := & Pusher {
53
+ producer : producer ,
54
+ topic : topic ,
55
+ }
56
+
57
+ // if enableSyncPush is true, return the pusher directly
58
+ if options .enableSyncPush {
59
+ return pusher
60
+ }
61
+
49
62
// apply ChunkExecutor options
50
63
var chunkOpts []executors.ChunkOption
51
64
if options .chunkSize > 0 {
@@ -55,10 +68,6 @@ func NewPusher(addrs []string, topic string, opts ...PushOption) *Pusher {
55
68
chunkOpts = append (chunkOpts , executors .WithFlushInterval (options .flushInterval ))
56
69
}
57
70
58
- pusher := & Pusher {
59
- producer : producer ,
60
- topic : topic ,
61
- }
62
71
pusher .executor = executors .NewChunkExecutor (func (tasks []interface {}) {
63
72
chunk := make ([]kafka.Message , len (tasks ))
64
73
for i := range tasks {
@@ -119,3 +128,10 @@ func WithAllowAutoTopicCreation() PushOption {
119
128
options .allowAutoTopicCreation = true
120
129
}
121
130
}
131
+
132
+ // WithEnableSyncPush enables sync push.
133
+ func WithEnableSyncPush () PushOption {
134
+ return func (options * pushOptions ) {
135
+ options .enableSyncPush = true
136
+ }
137
+ }
0 commit comments