@@ -104,8 +104,6 @@ type Fluent struct {
104
104
Config
105
105
106
106
dialer dialer
107
- // stopRunning is used in async mode to signal to run() it should abort.
108
- stopRunning chan struct {}
109
107
// cancelDialings is used by Close() to stop any in-progress dialing.
110
108
cancelDialings context.CancelFunc
111
109
pending chan * msgToSend
@@ -176,7 +174,6 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
176
174
f = & Fluent {
177
175
Config : config ,
178
176
dialer : d ,
179
- stopRunning : make (chan struct {}),
180
177
cancelDialings : cancel ,
181
178
pending : make (chan * msgToSend , config .BufferLimit ),
182
179
pendingMutex : sync.RWMutex {},
@@ -200,27 +197,26 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
200
197
//
201
198
// Examples:
202
199
//
203
- // // send map[string]
204
- // mapStringData := map[string]string{
205
- // "foo": "bar",
206
- // }
207
- // f.Post("tag_name", mapStringData)
200
+ // // send map[string]
201
+ // mapStringData := map[string]string{
202
+ // "foo": "bar",
203
+ // }
204
+ // f.Post("tag_name", mapStringData)
208
205
//
209
- // // send message with specified time
210
- // mapStringData := map[string]string{
211
- // "foo": "bar",
212
- // }
213
- // tm := time.Now()
214
- // f.PostWithTime("tag_name", tm, mapStringData)
215
- //
216
- // // send struct
217
- // structData := struct {
218
- // Name string `msg:"name"`
219
- // } {
220
- // "john smith",
221
- // }
222
- // f.Post("tag_name", structData)
206
+ // // send message with specified time
207
+ // mapStringData := map[string]string{
208
+ // "foo": "bar",
209
+ // }
210
+ // tm := time.Now()
211
+ // f.PostWithTime("tag_name", tm, mapStringData)
223
212
//
213
+ // // send struct
214
+ // structData := struct {
215
+ // Name string `msg:"name"`
216
+ // } {
217
+ // "john smith",
218
+ // }
219
+ // f.Post("tag_name", structData)
224
220
func (f * Fluent ) Post (tag string , message interface {}) error {
225
221
timeNow := time .Now ()
226
222
return f .PostWithTime (tag , timeNow , message )
@@ -380,7 +376,6 @@ func (f *Fluent) Close() (err error) {
380
376
f .pendingMutex .Unlock ()
381
377
382
378
if f .Config .ForceStopAsyncSend {
383
- close (f .stopRunning )
384
379
f .cancelDialings ()
385
380
}
386
381
@@ -513,7 +508,7 @@ func (f *Fluent) run(ctx context.Context) {
513
508
for {
514
509
select {
515
510
case entry , ok := <- f .pending :
516
- // f.stopRunning is closed before f.pending only when ForceStopAsyncSend
511
+ // The context is cancelled before f.pending only when ForceStopAsyncSend
517
512
// is enabled. Otherwise, f.pending is closed when Close() is called.
518
513
if ! ok {
519
514
f .wg .Done ()
@@ -540,9 +535,9 @@ func (f *Fluent) run(ctx context.Context) {
540
535
}
541
536
f .AsyncResultCallback (data , err )
542
537
}
543
- case <- f .stopRunning :
538
+ case <- ctx .Done ():
539
+ // Context was canceled, which means ForceStopAsyncSend was enabled
544
540
fmt .Fprintf (os .Stderr , "[%s] Discarding queued events...\n " , time .Now ().Format (time .RFC3339 ))
545
-
546
541
f .wg .Done ()
547
542
return
548
543
}
0 commit comments