Re: [go-nuts] Re: Is there any ways to kill goroutine immediately ?

2018-01-11 Thread Ian Lance Taylor
On Thu, Jan 11, 2018 at 9:02 AM,   wrote:
> A `return` should kill it.

Or runtime.Goexit (https://golang.org/pkg/runtime/#Goexit).

Ian

> On Thursday, 11 January 2018 15:50:24 UTC, Iman Tumorang wrote:
>>
>> I'm using goroutine with 2 concurrent jobs.
>>
>> And I've using context with both of the goroutine.
>>
>> I use
>> context.WithTimeout
>>
>>
>> func (u *feedUsecase) fetchDataWithContext(ctx context.Context, location
>> string, fc chan feedChan) {
>>   go func() {
>>  for {
>>select {
>>case <-ctx.Done():
>> fc <- feedChannel{
>> Err: ctx.Err,
>> Data: nil,
>> }
>> return
>> default:
>> // Calling another API
>> fc <- resultFromAPI
>> return
>> }
>> }
>>
>>
>>
>> I've succeeded to stop the waiting for the response of the function that
>> uses the goroutine.
>>  And returning the error: context exceeded. But later I found that the
>> goroutine still exists until it's finished the process.
>>
>>
>> Is there any ways to kill immediately the goroutine??
>>
>> I mean, some tricks or ways to kill all the process immediately in
>> function : fetchDataWithContext
>>
>>
>> Thank you.
>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Is there any ways to kill goroutine immediately ?

2018-01-11 Thread gary . willoughby
A `return` should kill it.

On Thursday, 11 January 2018 15:50:24 UTC, Iman Tumorang wrote:
>
> I'm using goroutine with 2 concurrent jobs. 
>
> And I've using context with both of the goroutine. 
>
> I use  
> context.WithTimeout
>
>
> func (u *feedUsecase) fetchDataWithContext(ctx context.Context, location 
> string, fc chan feedChan) {
>   go func() {
>  for {
>select {
>case <-ctx.Done():
> fc <- feedChannel{
> Err: ctx.Err,
> Data: nil,
> }
> return 
> default:
> // Calling another API
> fc <- resultFromAPI
> return
> }
> }
>
>
>
> I've succeeded to stop the waiting for the response of the function that 
> uses the goroutine.
>  And returning the error: context exceeded. But later I found that the 
> goroutine still exists until it's finished the process. 
>
>
> Is there any ways to kill immediately the goroutine??
>
> I mean, some tricks or ways to kill all the process immediately in 
> function : fetchDataWithContext
>
>
> Thank you.
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.