Тёмный

How To Use Goroutines For Aggregating Data In Golang?! 

Anthony GG
Подписаться 56 тыс.
Просмотров 34 тыс.
50% 1

► 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

Опубликовано:

 

20 ноя 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@bryant2040
@bryant2040 Год назад
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 4 месяца назад
thanks, I have struggled a bit to understand the whole concept of goroutines, channels and wait groups, but this cleared all doubts.
@alexsandersilva7402
@alexsandersilva7402 10 дней назад
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 2 месяца назад
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.
@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.
@augustocaro43
@augustocaro43 8 месяцев назад
This is the best example on Golang concurrency I could ever come across. Period.
@wmatheushenriq
@wmatheushenriq 9 месяцев назад
Excellent explanation!! Thank you
@nikolabosnjak9991
@nikolabosnjak9991 Год назад
Great explanation. Thanks!
@sovrinfo
@sovrinfo Год назад
Awesome video. Thanks!
@naveedurrehman9914
@naveedurrehman9914 11 месяцев назад
its very informative video indeed. thank you sir
@seanknowles9985
@seanknowles9985 Год назад
Quality videos for the fans!
@terjemah_alquran
@terjemah_alquran 10 месяцев назад
i really enjoy how you tell something with some jokes, thank you 🤣
@PramodSetlur
@PramodSetlur Месяц назад
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_ Месяц назад
Channels are syntactic sugar. Thats all being handled by the compiler.
@hassanad94
@hassanad94 19 дней назад
Thanks finally i understand it :)
@sanjarmatin6227
@sanjarmatin6227 Месяц назад
Good job man 😊
@monawwarabdullah7438
@monawwarabdullah7438 Год назад
thanks for sharing !!
@faisalmushtaq2287
@faisalmushtaq2287 10 месяцев назад
Awesome video, Thanks. Must say that all other videos on goroutines on YT are useless except for yours.
@codertjay
@codertjay 8 месяцев назад
love this channel
@Jackbeti
@Jackbeti Год назад
Perfectly ❤
@benkogan1579
@benkogan1579 Месяц назад
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.
@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 6 месяцев назад
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 6 месяцев назад
@@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?
@hmls3579
@hmls3579 8 месяцев назад
what could be a good match for Bob? Alice! goddamn Alice!!!
@annguyen6166
@annguyen6166 11 месяцев назад
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
@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.
@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?
@xelesarc1680
@xelesarc1680 7 месяцев назад
Thats a good example maybe with real database con reall and some call api too
@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
@ryanleemartin7758
@ryanleemartin7758 Год назад
"it waiting but it never comes... just like your gf". ☠
@dmitriyobidin6049
@dmitriyobidin6049 3 месяца назад
What if we need to zip responses from 2 different channels.
@hectoralvarado9778
@hectoralvarado9778 9 месяцев назад
Understood everything except the part of GF what is a GF it's a Type or library??
@anthonygg_
@anthonygg_ 9 месяцев назад
Girlfriend
@twitchizle
@twitchizle 3 месяца назад
​@@anthonygg_you missed the joke damn
@gusary8439
@gusary8439 8 месяцев назад
i still dont understand how to handle if function userLikes returns string and error (not only 1 return)
@davidblake8612
@davidblake8612 2 месяца назад
I dunno either, but maybe a user defined struct of response and error? Make the chan of that type?
@alexmeh1919
@alexmeh1919 4 месяца назад
🤙🤙🤙
@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.
@manojsinghnegi1565
@manojsinghnegi1565 7 месяцев назад
🤙🤙🤙🙏🏽🧐
@rahulsriram6295
@rahulsriram6295 Год назад
so this is equivalent to Promise.all in JS?
@mimamch
@mimamch 8 месяцев назад
I have same opinion
Далее
How To Test HTTP Handlers In Golang?!
14:28
Просмотров 18 тыс.
Beginners Should Think Differently When Writing Golang
11:35
Заметили?
00:11
Просмотров 1,3 млн
How To Structure Your Golang (API) Projects!?
20:28
Просмотров 43 тыс.
Setup HTTP Server & Router from scratch in Golang
36:41
Why You Shouldn't Nest Your Code
8:30
Просмотров 2,5 млн
Go Pointers: When & How To Use Them Efficiently
14:09
How I Structure New Projects In Golang
21:32
Просмотров 49 тыс.
A Practical Example How To Use Interfaces In Golang
14:42