learn the Go concurrency pattern that blew my mind
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- Golang, Go Programming concurrency patterns continued
🌟 Hey devs! 🌟
Ready to level up your coding game? Check out this awesome course on Microservices using Go!
🚀 From beginner to pro, learn to build scalable apps with ease. Don't miss out!
Enroll now: 👉 kantan-coding....
#golanguage #Microservices #CodeWithConfidence 🔥🎉
Join the Discord to talk to me and the rest of the community!
/ discord
Book on Concurrency in Go: www.oreilly.co...
Your videos about concurrency in Go are very good.
Thank you! I’m glad that they are helpful 😊
I was always confused with orDone, now its clear, Thank you!
And appreciate the last piece of explaining the complete code as a snippet,that was helpful.
Thanks for watching! I’m glad it was helpful 😊
Your teaching style is very good specially with conceptual diagram before or after coding. That is something not many youtuber do.
Thank you! I’m happy it was helpful
Congratulations on your course! I've been following you since your clean architecture videos, which were an absolute game changer for my mindset. Definitely going to try and save up time and money for this course. In the meantime thanks for all your splendid free content.
I have never never never considered purchasing a course, and especially not in a language Ive been learning almost since when your content started but if you're interested, I feel like I'm not doing enough vanilla stuff at my current company and it's debilitating and I have never actually taken a microservice to production all by myself before, so even more debilitating.
Hey! Thank you so much for your support. I’ll still be posting plenty of free content as well so stay tuned😊
P.s. it really means a lot to me that you’ve stuck around for so long. Thank you for telling me. It made my day 🙂
Of course, you're an inspiration, and please, keep it going!@@kantancoding
best explanations on go concurrency i found on TH-cam
This is an interesting concept. Thanks for sharing.
My pleasure!
I like this pattern, wish this were a builtin in Go.
one thing - wouldn't it be better to use generic types in the signature of orDone so that you're not losing type info by wrapping the channel?
Awesome,u r back with a bang !!!
Life got a bit busy but I’m back! Stay tuned for more videos 😊
@@kantancoding do more videos on teh topics like performance analysis and a typical tech stack what used mostly in the production or based on your experience, that will really give some insights which really helps budding Go lang devs.
Perf analysis sounds fun. Let me see what I can come up with
Hi @kantancoding, great video and that’s a pattern I’ll look to use in my concurrency projects.
It’s very useful!
Why not make use a `context.Context`? It is the same functionality but with better ergonomics and broader support.
Yes, you are absolutely correct my friend. Good insight 😉
Basically, this video is to teach the orDone pattern. The context package needs its own entirely separate video (which I am currently making). I did not want to convolute the explanation of the orDone pattern with context package stuff.
But! for those that want to jump ahead, this is what the code looks like replacing the done channel with the context package(the pattern does not change):
package main
import (
"context"
"fmt"
"sync"
)
var wg sync.WaitGroup
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cows := make(chan interface{}, 100)
go func() {
for {
select {
case
nested selects made me feel sad :D Sometimes repetitive/verbose code is way cheaper and easier to maintain than smart abstractions.
Hmm, there's a discussion about this in the pinned comment where I responded to a similar comment if you're interested. But aside from that, thanks for watching and contributing 😊
what you said is actually the go way
isn't there another more common pattern (i.e. in other languages) suitable for the "orDone" function ?
I'd imagine a decorator pattern will suffice without the extra relay chan
Where can i find the code samples?
I feel like this pattern should be called untilDone rather than orDone. For example:
for val in range untilDone
linguistically makes more sense than
for val in range orDone
Calling it orDone tells me that we're either doing something or we're not doing something. Calling it untilDone tells me that we're doing something UNTIL we're not doing something, essentially doing the thing until the thing is done rather than doing the thing or not doing the thing.
I kind of feel like "range until done" implies that we will in fact range. But if the channel is closed we won't range at all.
that's why I think "range or done" is used. We'll range if the channel isn't closed or we'll be done.
But of course, naming is subjective and is probably the most difficult part of programming 😆
The name "orDone" is more aligned with concepts from functional programming, like "maybe".
Good work here.
Thank you! Cheers!
Why would you need two select statements in the orDone function instead of using an additional case? Is there a language rule for this use case?
Hi, I explain this in the video 🙂
Can u please upload that microservice in go in your youtube also
🤔 sorry, I cannot. That wouldn’t be fair to the people that have paid for the course.
Bro stop making every video about concurrency in go
Bro, I’m not AI. You can’t give me orders 😂🤣
Anyways, what types of videos do you want to see?
@@kantancodingPls don't listen to him... we're enjoying it 😎