Golang Context Explained - How To Use With Timeout

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ย. 2023
  • 🔍 If you're a Go developer looking to improve your understanding of context management and concurrency control, you're in the right place.
    In this video, we break down the fundamentals of the Golang Context package, exploring its core concepts, practical applications, and best practices. Whether you're a beginner or an experienced Go developer, this tutorial has something valuable to offer.
    Twitch
    I stream live on Twitch every weekend
    Twitch : / melkey
    Join the amazing community on Discord
    Discord: / discord
    I post memes and host Twitter Tech Spaces
    Twitter: / melkeydev
    SUBSCRIBE OR GET LAID OFF
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #neovim #typescript #programming #vim #softwareengineering #codinglife #webdesign #webdevelopment #webdev #javascript #rustlang #rust #twitch #twitchstreamer #programmerhumor #codinghumor #software #softwareengineer #softwaredeveloper #softwaredevelopment #gymbro #gym #programmerhumor #programming #coding #golang #go #goprogramming
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 32

  • @MelkeyDev
    @MelkeyDev  10 หลายเดือนก่อน +16

    I hope you all loved this video! Leave a like, comment, like + subscribe. It means the world to me. Let me know what video you want to see in the future!

  • @JohannesLuebke
    @JohannesLuebke 7 หลายเดือนก่อน +34

    But are we still waiting for 400ms? We are just not returning the result but an error right? Or how do we reach the ctx.Err() check before the 400ms run out?

  • @Urgleflogue
    @Urgleflogue 4 หลายเดือนก่อน +9

    You should put the long call in a goroutine with a loop and switch. What you've done here is not what contexts are for, you could've just measure the elapsed time and return error or otherwise.

    • @ashleyspianoprogress1341
      @ashleyspianoprogress1341 3 หลายเดือนก่อน +1

      Could you provide an example? This is what I'm trying to do right now and struggling

    • @Urgleflogue
      @Urgleflogue 3 หลายเดือนก่อน

      @@ashleyspianoprogress1341 th-cam.com/video/kaZOXRqFPCw/w-d-xo.html

  • @0xZeeS
    @0xZeeS 10 หลายเดือนก่อน +33

    Great video!
    However, example could be better - since the function still blocks until the time it takes for the API call. I.e. if API call blocked for an hour, you'd need to wait for the whole hour, only to encounter deadline exceeded error.
    ^ Nevertheless, this vid presents a good starting point!

    • @kartashuvit4971
      @kartashuvit4971 10 หลายเดือนก่อน +1

      where would you error using the context in that case?

    • @tayyab0987
      @tayyab0987 9 หลายเดือนก่อน

      @@kartashuvit4971 have a for loop checking for the error then kill the http request

  • @devfortunato
    @devfortunato 2 หลายเดือนก่อน +4

    You should have used a goroutine with a select statement and check the ctx.Done() or the result. What are you doing in the example is just waiting for the result and throwing away if the time is exceed.

  • @ronny584
    @ronny584 5 หลายเดือนก่อน +5

    A video that is 8 minutes long with a trash thumbnail, ends up with a trash example. This channel is cooked lmao.

  • @wsollers1
    @wsollers1 9 หลายเดือนก่อน

    Nice video. Simple to the point

  • @emil_l889
    @emil_l889 10 หลายเดือนก่อน +1

    Context is really cool actually, good stuff

  • @rafaelacioly3252
    @rafaelacioly3252 10 หลายเดือนก่อน +5

    If the func in sleeping for 400ms (didn't reach the if statement) and the context is cancelled, how the "context timeout exceeded" error is reached?

    • @hakooplayplay3212
      @hakooplayplay3212 8 หลายเดือนก่อน +9

      it actually not canceled and continue to work. its just throw result out, because its too late. So this example is trash :) you actually need to cancel this function call in mid air if time is exceeded, so you need to run it in gorutine and wait outside in select for result or ctx.Done(), to not wait for this call to return something in a minute for example to just throw it away.

  • @BanAaron
    @BanAaron 10 หลายเดือนก่อน +9

    Could you boost the audio levels on your videos? I have to have my laptop speakers at 100% to be able to hear clearly, it is only with your videos

    • @Kane0123
      @Kane0123 10 หลายเดือนก่อน +1

      Laptop speakers? Gotta get that upgraded player!

  • @a_storyy_teller
    @a_storyy_teller 6 หลายเดือนก่อน

    your explanation is awesome bro

    • @MelkeyDev
      @MelkeyDev  6 หลายเดือนก่อน

      Thank you so much 😀

  • @JohnBrosan
    @JohnBrosan 10 หลายเดือนก่อน

    Great video! Any chance you can provide something on Authentication/Authorization with Go? Thanks!

  • @notoriouslycuriouswombat
    @notoriouslycuriouswombat 10 หลายเดือนก่อน

    MELKEY MELKEY MELKEY

  • @emil_l889
    @emil_l889 10 หลายเดือนก่อน +3

    Only context go needs is enums, sadge

  • @sjc5
    @sjc5 5 หลายเดือนก่อน

    Thanks for the great content. It would be nice to have less jumping around between zoomed in text editor / your camera / split view. Just sticking to split view would be easier to watch / follow. Thanks again.

    • @MelkeyDev
      @MelkeyDev  5 หลายเดือนก่อน +1

      Thanks for the feedback - Will do this for my next tutorial :)

  • @rosehogenson1398
    @rosehogenson1398 10 หลายเดือนก่อน

    Great examples as always, Melkey

  • @johnpeterson8493
    @johnpeterson8493 10 หลายเดือนก่อน +1

    how far are you in Berserk?

    • @MelkeyDev
      @MelkeyDev  9 หลายเดือนก่อน

      All caught up again

  • @emil_l889
    @emil_l889 10 หลายเดือนก่อน

    Used my actual userID😮

  • @ed223-p5g
    @ed223-p5g 10 หลายเดือนก่อน +1

    fix the audio pls

  • @thewhiteoaktree
    @thewhiteoaktree 10 หลายเดือนก่อน +2

    How do I get the values of an associative array in PHP?

    • @bumpy_lumps
      @bumpy_lumps 10 หลายเดือนก่อน +2

      i think it's in the go docs somewhere

    • @loohbiidloo4753
      @loohbiidloo4753 10 หลายเดือนก่อน +2

      arr[“key” => “value”]
      $value = arr[“key”]

  • @jeffreysmith9837
    @jeffreysmith9837 2 หลายเดือนก่อน +1

    this is not it. your time.Sleep() is blocking