reugn / go-streams

A lightweight stream processing library for Go

Home Page:https://pkg.go.dev/github.com/reugn/go-streams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graceful shutdown

nikolay-turpitko opened this issue · comments

In all examples the main go-routine either blocks forever or waits for timeout.

Is there any way to gracefully exit main function once processing completes (but not aborting all currently running go-routines until they finish the job)? I can do it with ChanSink and using some sync primitive inside it, but it looks a bit ugly. Any nicer solution?

Hi @nikolay-turpitko. A workflow is active as long as an Outlet(Source) channel is open. With simple source examples like reading from a file, the flow will complete writing to a sink and then terminate. With the streaming sources (and sinks), the flow is expected to be active constantly and could be terminated either by a Source error or sigterm. The wait call in the examples is redundant since each flow blocks on the To(sink) call. Hope this helps.

Yeah, it works. There was a mistake in my code. I tried to use ext.ChanSync with channel, which I pass to another blocking function.

BTW, I'm trying to connect existing function (could be 3rd party API), which accepts typed channel like chan CustomMessage, but go-streams operate over chan interface{}. I had to write explicit go-routine with a loop, passing everything from one channel to another. Looks a bit ugly. Do you know any better way by any chance?