Relative Content

Tag Archive for goconcurrencygoroutine

Concurrently in Go

In this code, function fn() should be executed 2 times every 200ms (the interval depends on the limit value). How to limit the number of calls?

[Golang]: Goroutine cancelation mid-execution

I was watching the Rob Pike’s fascinating talk called “Concurrency is not Parallelism” and I was trying to extend the example with concurrent queries, but it seems that I don’t fully understand how goroutines work. In particular, I don’t understand how to cancel the goroutine during its execution.

Should I use goroutines for subflows or execute them sequentially in Go?”

The situation is the following: I have a web application in Go written with Gin (I think it doesn’t matter the framework). Then, as it is known, each incoming request is served by a goroutine. One of the endpoints has a flow in which a subflow must be done internally several times (from 45 to 500 times, usually closer to the lower limit). This subflow consists of three operations: an http request and aand two MongoDB operations. To continue with the main flow I have to wait for all the subflows to finish (they are done transactionally moreover, this I handle directly with the Mongo driver). So, according to me, I have 2 ways: