Golang Channels Or Wait Groups? Let Me Explain.

Golang Channels Or Wait Groups? Let Me Explain.

Anthony GG

6 месяцев назад

17,188 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@kangtran3008
@kangtran3008 - 02.01.2024 17:47

What's the color theme are you using?
Thanks

Ответить
@ashishDandgawhale
@ashishDandgawhale - 25.12.2023 15:24

Im wondering why the wg.done() was not called? and without that how did the wg know that all goroutes are comeplted?

Ответить
@HiperCode10100
@HiperCode10100 - 23.12.2023 21:54

If I apply to be a partner on the website, are there translation subtitles? thai😢

Ответить
@EricT43
@EricT43 - 17.12.2023 04:27

From now on I am calling my wait groups "weegee" :D

Ответить
@italoservio
@italoservio - 08.12.2023 04:53

Amazing video! I learned to add the waiter and the close into an anonymous go routine and keep the code out of the anonymous go routine.
Thanks for this rich material

Ответить
@redsnakeintown
@redsnakeintown - 27.11.2023 09:30

Done decrement the number inside the wg.add

Ответить
@kevinz1991
@kevinz1991 - 25.11.2023 13:50

super clear and easy to understand thank u

Ответить
@matiasbpg
@matiasbpg - 23.11.2023 01:18

I think you could skip the wg in the last example by using just an int that is decremented inside the for loop and making the loop sync inside the main. When the last value is received and the counter is zero, just close the channel and the execution of the main function continues

Ответить
@errorbat
@errorbat - 23.11.2023 01:12

What about the switch{} block and label brakes in for loop instead of using the waitgroups along with channels?

Ответить
@mansourbaitar5194
@mansourbaitar5194 - 22.11.2023 13:59

YOU ARE HIM

Ответить
@bhavin19
@bhavin19 - 22.11.2023 09:38

Hmm, shouldn't it be better if we just defer the Chan closing instead of using sleep?

Ответить
@alexandrk5715
@alexandrk5715 - 22.11.2023 08:01

Volume becomes lower and lower with every next video, please make it at least a little bit louder, it's becoming hard to listen. Thanks for your work.

Ответить
@0xastley
@0xastley - 22.11.2023 06:43

When you demonstrated channels, I think you can make(chan string, size) so you can mimick the config you had with waitgroups. You'll only be expecting 3 messages into the channel and then close it.

Ответить
@vanshajdhar9223
@vanshajdhar9223 - 22.11.2023 05:18

Best video on channels and waitgroups ❤

Ответить
@amitkumdixit
@amitkumdixit - 22.11.2023 04:45

Why don't we add wg.Done in the local function instead of sleep

Ответить
@fdefontis
@fdefontis - 22.11.2023 00:49

Great video, both well explained and helpful, thank you!

Ответить
@kronst
@kronst - 22.11.2023 00:04

Are there any disadvantages of using this approach? For example if we need to make multiple parallel requests to fetch different type of results.

func main() {
start := time.Now()

var r1 string
var r2 int
var r3 time.Time

wg := sync.WaitGroup{}
wg.Add(3)

go func(wg *sync.WaitGroup) {
r1 = "Hello"
time.Sleep(1 * time.Second)
wg.Done()
}(&wg)

go func(wg *sync.WaitGroup) {
r2 = 42
time.Sleep(2 * time.Second)
wg.Done()
}(&wg)

go func(wg *sync.WaitGroup) {
r3 = time.Now()
time.Sleep(3 * time.Second)
wg.Done()
}(&wg)

wg.Wait()

fmt.Println(r1, r2, r3)
fmt.Printf("took: %v\n", time.Since(start))
}

Ответить
@athinodorossgouromalliis9021
@athinodorossgouromalliis9021 - 22.11.2023 00:02

GG video man. When I was learning golang the when to use go routines with channels was a bit hard to understand and I wish your video was out back then! Cheers mate good job

Ответить
@ghoulbond
@ghoulbond - 21.11.2023 21:59

Thanks Anthony, just a quick question

is it a possible to close the channel inside the go routine in this way

go func() {
for res := range resultch {
fmt.Println(res)
}

fmt.println()
close(resultch)
}()

if it is possible, is it considered a good practice?

Ответить
@troymadsen9845
@troymadsen9845 - 21.11.2023 21:41

Would it make sense to invert your example, pass the wg.Wait to your anonymous function and have the channel for on the main thread to get results back to main thread? I suppose you could also pass a slice to the function instead of the wg

Ответить
@shivamkumarz
@shivamkumarz - 21.11.2023 19:55

Please make a video on different rate limiting patterns

Ответить
@wMwPlay
@wMwPlay - 21.11.2023 19:28

But it feels like using both channels with waitgroups are taking more resources. Didn't test myself but heard using channels is much efficient and preffered than wg. Any other approaches to control that job is done? contexts?

Ответить
@jamesblackman1623
@jamesblackman1623 - 21.11.2023 18:55

Great - really good simple demo - thanks

Ответить
@demyk214
@demyk214 - 21.11.2023 18:25

Nee maat gewoon assembly

Ответить
@saifbenzamit5980
@saifbenzamit5980 - 21.11.2023 18:12

G.O.A.T as always ❤

Ответить
@aamonaze
@aamonaze - 21.11.2023 18:08

legend back

Ответить
@ZhaksylykAshim
@ZhaksylykAshim - 21.11.2023 17:55

pls make a video about fan-in, fan-out patterns and usage of select keyword when working with multiple channels (also would be great if buffers, read and write chanells would be also discussed). My appreciation, maestro!

Ответить
@worldwide6626
@worldwide6626 - 21.11.2023 17:37

2

Ответить
@it1860
@it1860 - 21.11.2023 17:28

1

Ответить