How To Use Goroutines For Aggregating Data In Golang?!

  Рет қаралды 35,011

Anthony GG

Anthony GG

Жыл бұрын

► Join my Discord community for free education 👉 / discord
► Become a Patreon for exclusive tutorials👉 / anthonygg_
► Follow me on Twitter 👉 / anthdm
► Follow me on GitHub 👉 github.com/anthdm
In this Golang tutorial, I will teach how you can use go routines for aggregating data and how to synchronize them.
#programming #golang

Пікірлер: 61
@anthonygg_
@anthonygg_ Жыл бұрын
► Join my Discord community for free education 👉 discord.com/invite/bDy8t4b3Rz ► Become a Patreon for exclusive tutorials👉 www.patreon.com/anthonygg_ Thanks for watching
@kiboit
@kiboit Жыл бұрын
That subtle GF joke totally sent me 🤣🤣You said it without flinching too. Thank you for this , its actually really helpful
@anthonygg_
@anthonygg_ Жыл бұрын
🙏
@fersalamanca2606
@fersalamanca2606 5 ай бұрын
thanks, I have struggled a bit to understand the whole concept of goroutines, channels and wait groups, but this cleared all doubts.
@augustocaro43
@augustocaro43 9 ай бұрын
This is the best example on Golang concurrency I could ever come across. Period.
@jameslapointe3044
@jameslapointe3044 Жыл бұрын
Great video that helped my a lot make sense. At times - you seem to be running too hot trying to explain/do too much but at end I understood everything.
@wmatheushenriq
@wmatheushenriq 10 ай бұрын
Excellent explanation!! Thank you
@nikolabosnjak9991
@nikolabosnjak9991 Жыл бұрын
Great explanation. Thanks!
@alexsandersilva7402
@alexsandersilva7402 28 күн бұрын
Great. I'm learning Go and using channels, go routines and waitgroups to read and check information from multiple files. I'm using select and a quit channel to control the end of processing.
@kke
@kke Жыл бұрын
Or you could just do `resp := make(any, 2); for i := range resp { resp[i] =
@anthonygg_
@anthonygg_ Жыл бұрын
True! Thanks for this.
@KACP1999
@KACP1999 Жыл бұрын
@kke can you explain how this works:) ?
@kke
@kke Жыл бұрын
@johnxisde
@johnxisde Жыл бұрын
@kke thank you for this tip!
@gmeister3022
@gmeister3022 3 ай бұрын
In this case, you're right. But it's only viable if the number is static (in this example, the size of the buffer is 2). We would've had a different case if it was an unbuffered channel.
@sovrinfo
@sovrinfo Жыл бұрын
Awesome video. Thanks!
@naveedurrehman9914
@naveedurrehman9914 Жыл бұрын
its very informative video indeed. thank you sir
@terjemah_alquran
@terjemah_alquran 11 ай бұрын
i really enjoy how you tell something with some jokes, thank you 🤣
@seanknowles9985
@seanknowles9985 Жыл бұрын
Quality videos for the fans!
@monawwarabdullah7438
@monawwarabdullah7438 Жыл бұрын
thanks for sharing !!
@hassanad94
@hassanad94 Ай бұрын
Thanks finally i understand it :)
@sanjarmatin6227
@sanjarmatin6227 2 ай бұрын
Good job man 😊
@faisalmushtaq2287
@faisalmushtaq2287 11 ай бұрын
Awesome video, Thanks. Must say that all other videos on goroutines on YT are useless except for yours.
@codertjay
@codertjay 9 ай бұрын
love this channel
@Jackbeti
@Jackbeti Жыл бұрын
Perfectly ❤
@benkogan1579
@benkogan1579 2 ай бұрын
Wait group is one way to solve this. Another is to just iterate over the number of tasks (2) and receive from the channel. No need to close, it will get GC'ed as usually.
@hmls3579
@hmls3579 9 ай бұрын
what could be a good match for Bob? Alice! goddamn Alice!!!
@PramodSetlur
@PramodSetlur 2 ай бұрын
Great videos, thank you for them! I have a question: How come the channel itself is being passed around to various functions, and not the pointer to the channel? Wouldn't we need a pointer to the channel, so that the data is persistent once all the go routines complete? I guess I am missing something.
@anthonygg_
@anthonygg_ 2 ай бұрын
Channels are syntactic sugar. Thats all being handled by the compiler.
@annguyen6166
@annguyen6166 Жыл бұрын
Hi Anthony, very love your golang video. But i still don't known when we should use gorountine and handle gorountine correctly, can u help me
@vp--
@vp-- 9 ай бұрын
Hi , great explanation . Question : in this example when ranging over respch how do you know 1st item will be like or the match ? Is it random or in order of function calls ?
@embrace7972
@embrace7972 7 ай бұрын
same question
@marinm3869
@marinm3869 7 ай бұрын
Usually it depends, whichever function writes to the channel first. If you fetch from a remote resource you don't know what value will be written to the channel first because you don't know the latency, but in this case you know the name will come first since the function sleeps 100 ms and then writes to the channel while the likes function sleeps for 150 and then writes. The order of the function call does not matter since they are concurrent. Hope i was clear :)
@embrace7972
@embrace7972 7 ай бұрын
@@marinm3869 Yes you are right. But what would happen in the case of an API calls? I would never know how much time it would take. Then how will I know which API call am I reading from the channel. How are we supposed to differentiate the values from the channel?
@xelesarc1680
@xelesarc1680 8 ай бұрын
Thats a good example maybe with real database con reall and some call api too
@muhammadfahad3483
@muhammadfahad3483 Ай бұрын
If we are querying from DB, I don't think goroutine would be much helpful since its an I/O operation.
@anthonygg_
@anthonygg_ Ай бұрын
Third party api
@muhammadfahad3483
@muhammadfahad3483 Ай бұрын
@@anthonygg_ I don't get it?
@alexmeh1919
@alexmeh1919 4 ай бұрын
🤙🤙🤙
@DillPL
@DillPL Жыл бұрын
If we know for how many routines we have to wait, why not use regular indexed for loop? what is the benefit of using the wait group? for i:= 0; i
@anthonygg_
@anthonygg_ Жыл бұрын
The waitgroup is used so we know when to close the channel. When I think about it, your approach could also work. But I thought showcasing "ranging over channels" and "sync.Waitgroup" was important.
@emzx111
@emzx111 Жыл бұрын
is it good practice to emit to same channel despite multiple different api calls?
@feryadialoi2244
@feryadialoi2244 11 ай бұрын
it is just a demo, you probably don't want to mix the response type with a generic one like any, or you actually can mix it by embracing the usage of a generic type
@dmitriyobidin6049
@dmitriyobidin6049 3 ай бұрын
What if we need to zip responses from 2 different channels.
@manojsinghnegi1565
@manojsinghnegi1565 8 ай бұрын
🤙🤙🤙🙏🏽🧐
@gusary8439
@gusary8439 9 ай бұрын
i still dont understand how to handle if function userLikes returns string and error (not only 1 return)
@davidblake8612
@davidblake8612 3 ай бұрын
I dunno either, but maybe a user defined struct of response and error? Make the chan of that type?
@hectoralvarado9778
@hectoralvarado9778 10 ай бұрын
Understood everything except the part of GF what is a GF it's a Type or library??
@anthonygg_
@anthonygg_ 10 ай бұрын
Girlfriend
@twitchizle
@twitchizle 4 ай бұрын
​@@anthonygg_you missed the joke damn
@ryanleemartin7758
@ryanleemartin7758 Жыл бұрын
"it waiting but it never comes... just like your gf". ☠
@rogerramjet69
@rogerramjet69 Жыл бұрын
how do you specify a key from the channel... say in the loop I just want to print likes...something like if respch.key == 'likes' print blah
@anthonygg_
@anthonygg_ Жыл бұрын
for key := range channel. So your that will be the key you are looking for.
@rogerramjet69
@rogerramjet69 Жыл бұрын
@@anthonygg_ hey mate that wont work... we havent assigned a key:value pair to each of those go routines. tried using make(chan map[string]any, 2) but seems very messy :/
@rogerramjet69
@rogerramjet69 Жыл бұрын
@@anthonygg_ i created a struct respch := make(chan UserStuff, 2) and then in the funcs i used UserStuff{key: "likes", value: 11} and UserStuff{key: "match", value: "ANNA"} which appears to work ok... not sure if there is a cleaner approach.
@anthonygg_
@anthonygg_ Жыл бұрын
@@rogerramjet69 You should be good. If you want to discus this more in-depth you maybe join my Discord community. That chats a bit better.
@seanturner7400
@seanturner7400 Жыл бұрын
@@rogerramjet69 I think that's a way cleaner approach to be honest, I thought any was really suss. I would create two structs however, `userLikes{likes: int, error: err}` and `userMatch{match: str, error:err}`. This pattern is more intentional and also lets you check for errors.
@rahulsriram6295
@rahulsriram6295 Жыл бұрын
so this is equivalent to Promise.all in JS?
@mimamch
@mimamch 9 ай бұрын
I have same opinion
How To Test HTTP Handlers In Golang?!
14:28
Anthony GG
Рет қаралды 18 М.
How To Build A Chat And Data Feed With WebSockets In Golang?
20:45
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 12 МЛН
When someone reclines their seat ✈️
00:21
Adam W
Рет қаралды 29 МЛН
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 1,8 МЛН
Master Go Programming With These Concurrency Patterns (in 40 minutes)
46:15
Golang's Mocking Techniques - Kyle Yost | hatchpad Huddle
41:20
Making the Best Framework in Golang Even Better
Anthony GG
Рет қаралды 74
Never write another loop again (maybe)
10:48
Dreams of Code
Рет қаралды 248 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 17 М.
A Practical Example How To Use Interfaces In Golang
14:42
Anthony GG
Рет қаралды 19 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 94 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
How To Build And Structure A Microservice In Golang?!
23:03
Anthony GG
Рет қаралды 46 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 12 МЛН