Skip to content

Commit

Permalink
cshared: Make backward compatible and interruptable goroutines
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 6, 2023
1 parent 5bd8020 commit cd2786a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ func prepareInputCollector() (err error) {

go func(theChannel chan<- Message) {
defer theInputLock.Unlock()

go func(theChannel chan<- Message) {
err = theInput.Collect(runCtx, theChannel)
}(theChannel)

for {
select {
case <-runCtx.Done():
log.Printf("goroutine will be stopping: name=%q\n", theName)
return
default:
err = theInput.Collect(runCtx, theChannel)
}
}

Expand Down Expand Up @@ -276,15 +279,18 @@ func FLBPluginOutputPreRun(useHotReload C.int) int {
runCtx, runCancel = context.WithCancel(context.Background())
theChannel = make(chan Message)
go func(runCtx context.Context) {
go func(runCtx context.Context) {
err = theOutput.Flush(runCtx, theChannel)
}(runCtx)

for {
select {
case <-runCtx.Done():
log.Printf("goroutine will be stopping: name=%q\n", theName)
return
default:
err = theOutput.Flush(runCtx, theChannel)
}
}

}(runCtx)

if err != nil {
Expand Down

0 comments on commit cd2786a

Please sign in to comment.