Member-only story

Go Routine

Concurrency in Go with calling API requests

Get to know goroutine.

Donald Le

--

Photo by Priscilla Du Preez on Unsplash

We’ll go over some API requests without go concurrency. For example we want to get data from

"https://www.ncbi.nlm.nih.gov/gene/?term=" + gene

Doing so without concurrency

Will cost

31.525466019s

So how do we use go concurrency?

first we need to create waitgroup

wg := sync.WaitGroup{}

Then before move into the go routine, we need to add

wg.Add(1)

Outside the for loop of routines, we wait

wg.Wait()

That’s it.

Running the code will only take

4.967423025s

Happy coding guys ~~~

--

--

No responses yet