Re: [go-nuts] Any good idea to stop the goroutine as soon as possible?

2022-01-11 Thread 'Axel Wagner' via golang-nuts
On Wed, Jan 12, 2022 at 3:01 AM E Z wrote: > Thank you very much. > > I understand that we can use context.Context to resolve the network > blocking problem in long-running function if the network library support > passing a context parameter. > > But for the CPU-bound code, Is the following imp

Re: [go-nuts] Any good idea to stop the goroutine as soon as possible?

2022-01-11 Thread E Z
Thank you very much. I understand that we can use context.Context to resolve the network blocking problem in long-running function if the network library support passing a context parameter. But for the CPU-bound code, Is the following implementation mentioned by axel the only way to make a

Re: [go-nuts] Any good idea to stop the goroutine as soon as possible?

2022-01-11 Thread Ian Lance Taylor
On Tue, Jan 11, 2022 at 12:15 PM 'Axel Wagner' via golang-nuts wrote: > > The best way to do this is to plumb a context.Context through all > long-running functions - in particular, anything talking to the network. > Most RPC and network frameworks provide a way to pass a Context, so > consisten

Re: [go-nuts] How to distribute database connection across all golang file ?

2022-01-11 Thread Chris Burkert
Hi, The standard sql package (https://pkg.go.dev/database/sql) comes with a connection pool. I think it is the DB struct handling the pool. The drivers which implement the details for a specific database product usually come with plenty of documentation and examples. See https://github.com/golang/g

Re: [go-nuts] Any good idea to stop the goroutine as soon as possible?

2022-01-11 Thread 'Axel Wagner' via golang-nuts
The best way to do this is to plumb a context.Context through all long-running functions - in particular, anything talking to the network. Most RPC and network frameworks provide a way to pass a Context, so consistently doing this will more or less transparently

[go-nuts] Any good idea to stop the goroutine as soon as possible?

2022-01-11 Thread E Z
I'm using golang to implement a task schedule and process system. I found that golang can't stop the goroutine externally, we must wait for the goroutine to end itself. I can stop a goroutine through a channel, however, the only time to check the value of the channel is when the select is call