golang context package explained: the package that changed concurrency forever

Поділитися
Вставка
  • Опубліковано 11 лют 2025
  • A very intuitive explanation of Golang's context package
    Become a Golang Expert With This Hands-On Golang Course 👉 kantancoding.io

КОМЕНТАРІ • 62

  • @kantancoding
    @kantancoding  9 місяців тому

    Become a Golang Expert With This Hands-On Golang Course 👉 kantancoding.io

    • @thisisreallyme3130
      @thisisreallyme3130 3 місяці тому

      Could someone link the “previous video required viewing?

    • @kantancoding
      @kantancoding  3 місяці тому

      @@thisisreallyme3130 this video is part of a series on Go Concurrency
      ua-cam.com/play/PL7g1jYj15RUNqJStuwE9SCmeOKpgxC0HP.html

  • @mouadh4726
    @mouadh4726 4 місяці тому +3

    i came looking to debug a global pointer, found this unrelated subject, you helped me understand a very usefull go routines skill, very concise and not annoying precise to the point explanations. Thank you man 🙏🏼

  • @sarthakjoshi3797
    @sarthakjoshi3797 4 місяці тому +2

    thanks for the mini series, really solidified my understanding around concurrency in go. lets GOOOO!

  • @LearnBedrockAI
    @LearnBedrockAI 4 місяці тому

    Your style of teaching is the best I've ever seen, you can tell you know this stuff instead of regurgutating the documentation like every other channel. I'll buy your microservices course as soon as I can

    • @kantancoding
      @kantancoding  4 місяці тому

      Hey, thank you so much for your kind words and support! It really motivates me to keep going :)

  • @JEREMIAHCoolkat
    @JEREMIAHCoolkat 11 місяців тому +1

    Thanks mate. I've enjoyed your video series on concurrency in GO. Nice and clear explanation. Very helpful. Keep on the good work.

    • @kantancoding
      @kantancoding  10 місяців тому

      Hey! Thanks for the encouragement. I’m glad you enjoyed it 😊

  • @NatiShen
    @NatiShen 7 днів тому

    That's a great video , there are no good videos really explaining the context package thanks a lot man ! Could you do a video about templating html ? Templ for example

  • @folklinoff
    @folklinoff 11 місяців тому

    Amazingly structured comprehensive video! Thank you very much

    • @kantancoding
      @kantancoding  11 місяців тому

      Thank you! Happy to help 😊

  • @Fr4zn2pirit
    @Fr4zn2pirit 11 місяців тому +2

    Glad you're back to making Go videos man... They're super useful

  • @rossthemusicandguitarteacher
    @rossthemusicandguitarteacher 8 місяців тому

    Great teaching I am going to buy the course.

    • @kantancoding
      @kantancoding  8 місяців тому

      Wonderful! I hope it is useful for you 😊

  • @spiraldynamics6008
    @spiraldynamics6008 2 місяці тому

    Very interesting !! Thank you !

  • @inaccessiblecardinal9352
    @inaccessiblecardinal9352 6 місяців тому

    Very well motivated and well explained.

  • @SanjeevKumar-nq8td
    @SanjeevKumar-nq8td 5 місяців тому

    Nicely explained 👏

  • @LeviElekes
    @LeviElekes 11 місяців тому

    🙏

  • @miningahsean886
    @miningahsean886 8 місяців тому

    This was really good. Thanks

  • @mountainer786
    @mountainer786 7 місяців тому

    really good explanation

  • @ujjwalkumar19
    @ujjwalkumar19 3 місяці тому

    Why we are not passing the address of context and stream to generic functions? Isn’t it creating new variables every time we call it?

  • @ShadwTrooper
    @ShadwTrooper 10 місяців тому

    Super helpful. Thanks!

  • @nickernara
    @nickernara 8 місяців тому

    @kantancoding thanks for nice visualisation
    my requirement is that main spawns multiple child (go routines) and
    if some thing goes wrong in any of the child then all child must abort right at the point what ever they are doing now
    and reported back to parent
    is errGroup coupled with context-with-cancel works in this scenario?
    if there exists any existing library it wud be really great, if not wanna make one to help dive deeper

  • @marioluigi2995
    @marioluigi2995 11 місяців тому +1

    hey man, welcome back, I'll watch your vid.

    • @kantancoding
      @kantancoding  11 місяців тому

      Thank you for watching! More to come 😊

  • @sinahassani9880
    @sinahassani9880 9 місяців тому

    This explanation is worth paying time for

    • @kantancoding
      @kantancoding  8 місяців тому

      Thank you! I’m glad it helped 🙂

  • @aamirshekh934
    @aamirshekh934 10 місяців тому

    can you do a video on ticker package and go sarama package. Both of them doesn't have any good resources on youtube.

    • @kantancoding
      @kantancoding  10 місяців тому

      not sure at the moment but I will keep it in mind! ☺️

  • @Porumb007
    @Porumb007 8 місяців тому

    Good explanation. Do you really need to duplicate the code for ctx cancel handling? Can't you have it in a separate function? Your function naming in the example is kind of bad.

  • @brandon_wallace
    @brandon_wallace 11 місяців тому

    Excellent!

  • @akash-tj8ru
    @akash-tj8ru 7 місяців тому

    11:40 Did u mean leaf go routines?

  • @anibaldk
    @anibaldk 2 місяці тому

    The content is superb but if you allow me a small critique:
    don't repeat yourself that much. It's a video. People can go back if unclear.

    • @kantancoding
      @kantancoding  2 місяці тому

      Yeah good point. Sometimes I forget that I already explained something and then I notice it while editing 😂

  • @jacobgtd2995
    @jacobgtd2995 7 місяців тому

    beast

  • @FaheemAfridi-n5n
    @FaheemAfridi-n5n 11 місяців тому +1

    Sir upload go tutorial for beginners

    • @kantancoding
      @kantancoding  11 місяців тому

      Hmm I have quite a few geared towards beginners. Is there anything specific you want to see?

    • @FaheemAfridi-n5n
      @FaheemAfridi-n5n 11 місяців тому

      @@kantancoding yes, I am beginner in programming. Golang is my first programming language

    • @kantancoding
      @kantancoding  11 місяців тому +1

      Introduction to Programming Using Go
      ua-cam.com/video/08Blkpo1F8I/v-deo.html

  • @dawnrazor
    @dawnrazor 8 місяців тому

    Great video, but what happens when you DO want to cancel a parent context from a child. I have this exact scenario and in this case I pass in the parents cancel to the child gr. this works fine but this seems to be going against the grain. How do you cancel the parent without passing cancel func? What is wrong with this?

    • @kantancoding
      @kantancoding  8 місяців тому +1

      I can’t think of any valid scenario where you’d cancel the parent from a child goroutine. I’d say the fact that you want/need to do this points out a fundamental design flaw in your application.
      I can help more if you tell me WHY you feel it is necessary to cancel the parent from the child.

    • @dawnrazor
      @dawnrazor 8 місяців тому

      @@kantancoding great thanks. I knew it was wrong but I couldn’t figure out how to fix it properly. I have designed a worker pool. The worker pool exposes an optional output channel that the client can read from for results. But if the client doesn’t define a consumer for the channel, then the pool will lockup. So I decided to introduce a feature that would timeout and allow the pool exit gracefully. I do this by allowing the worker to cancel the parent context so the whole pool including other workers to exit gracefully. Only the worker knows when the timeout occurs not the parent. How can I fix this? (gh/snivilised/lorax/boost/issues/68)

    • @kantancoding
      @kantancoding  8 місяців тому

      @@dawnrazorif you’re just using a timeout mechanism, just set the timeout in the context that you pass from the parent to the children using WithTimeout() (I explained how to use it in the video). Hope that helps!

    • @dawnrazor
      @dawnrazor 8 місяців тому

      @@kantancoding hi again, actually I don’t think your approach will work and the reason is this. The worker is running a task and there is no way to know how long the task will take. So what value do you set for the timeout in the parent context. There is no sensible value that you could come up with. And besides, the timer should only start at the point when the worker has attempted to sent to the output channel. Am I wrong about this?

    • @dawnrazor
      @dawnrazor 8 місяців тому +1

      @@kantancoding just wanna say thanks for making me realise that trying to cancel a parent from a child was totally wrong. I’m junking my entire worker pool and starting again with a better design

  • @Alfrednohike9909
    @Alfrednohike9909 11 місяців тому

    hiii, we missed you

  • @albizutoday2754
    @albizutoday2754 3 місяці тому

    Go is Google

  • @NigelTatschner
    @NigelTatschner 9 місяців тому

    You alllll get a context 😂

  • @rishirajrao5337
    @rishirajrao5337 8 місяців тому

    Honest feedback, it was bit verbose and was lacking clarity unlike other tutorials. Thanks anyway for the effort.