Skip to content
GolangFix

GolangFix

Find thousands of fixes for Go Language related issues. Daily Updated!

  • All Questions
  • GoLang
  • goroutine

Tag: channels

November 18, 2022 GoLang

How can one close a channel in a defer block safely?

Issue Consider the following example: package main import ( "fmt" "time" ) func main() { ticker := time.NewTicker(2 * time.Second) done := make(chan bool) defer func() { fmt.Println("exiting..") done <- true close(done) }() go func(ticker *time.Ticker, done chan bool) {

Continue reading
October 9, 2022 goroutine

Why is "Greetings done" getting printed before "Bonjour" in the below example of goroutines and channels?

Issue In the below example, Why is "Greetings done" getting printed before "Bonjour" ? Shouldn’t the sender routine wait until receiver routine receives the value in channel ? package main import ( "fmt" ) func greetings(c chan string) { fmt.Println(<-c)

Continue reading
September 18, 2022 GoLang

How can I explicitly empty a channel?

Issue The short version: Is there a way to empty a go channel without recreating it, or looping through it? The why: I’m using two channels to send and receive data, and I have an extra channel to signal that

Continue reading
September 18, 2022 GoLang

Clarification on Go channels tutorial from some missing word or words

Issue This page on a Go Tutorial about channels seems to be missing a word(s) or was just not edited. I can’t tell what it is supposed to say about sending and receiving through channels. By default, sends and receives

Continue reading
August 7, 2022 GoLang

Unable to loop through golang dynamic channels

Issue I want to loop through the menu’s options. However, it stops at the first option, since the select without "default:" is blocking and it does not know more options will appear dynamically. Bellow is the broken code: package main

Continue reading
August 2, 2022 GoLang

Using a GoLang Routine to Return to Multiple Threads

Issue I am building an API that can queue up requests to GET an external website and subsequently perform some work by interacting with that API. I am trying to figure out how to avoid duplicate simultaneous go routines. That

Continue reading
July 30, 2022 GoLang

Go: Performance Hit of Waiting for Multiple Channels

Issue I discovered something today that threw me for a bit of a loop, and I wanted to run it by the community to see if I’m missing something, or perhaps just designing things poorly. Use case: I have an

Continue reading
June 14, 2022 GoLang

Getting values inside an unmarshalled interface

Issue I have a websocket client that receives multiple data types. A function unmarshals json received from the server into different structs depending on the data received. The struct is then returned as an interface through a channel to my

Continue reading
June 2, 2022 GoLang

getting channel value from a webscoket client

Issue I’m running a websocket client and want to pass the response(s) from the client to a channel that i can work with in my main file. Currently, the channel just returns a nil value once and then nothing else.

Continue reading
May 24, 2022 GoLang

Sending to channel doesn't happen if select has default

Issue I am working on a personal project that will run on a Raspberry Pi with some sensors attached to it. The function that read from the sensors and the function that handle the socket connection are executed in different

Continue reading

Posts navigation

1 2 3 4 Next Posts»

amazon-web-services arrays channel concurrency deadlock dictionary docker error-handling generics go go-gin go-gorm go-modules go-templates goland google-cloud-platform goroutine grpc http interface json kubernetes linux mongo-go mongodb multithreading mysql pointers postgresql protocol-buffers python reflection regex slice sql string struct testing time type-conversion types unit-testing unmarshalling visual-studio-code windows

WordPress Theme: Maxwell by ThemeZee.

Privacy Policy - Terms and Conditions