Golang Context Explained - How To Use With Timeout

  Рет қаралды 22,714

Melkey

Melkey

Күн бұрын

Пікірлер: 36
@MelkeyDev
@MelkeyDev Жыл бұрын
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 11 ай бұрын
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?
@fyrofux
@fyrofux 3 ай бұрын
Great question. I thunk it should be pretty easy to reproduce and test
@tomas36181
@tomas36181 3 ай бұрын
@@fyrofux You're supposed to wait for the result in a separate goroutine and there's a way to check whether the context finished earlier than the func call. That way you're not waiting for no reason. This example is just bad.
@Urgleflogue
@Urgleflogue 8 ай бұрын
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 7 ай бұрын
Could you provide an example? This is what I'm trying to do right now and struggling
@Urgleflogue
@Urgleflogue 7 ай бұрын
@@ashleyspianoprogress1341 kzbin.info/www/bejne/oZK9gIuIpquDedk
@0xZeeS
@0xZeeS Жыл бұрын
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 Жыл бұрын
where would you error using the context in that case?
@tayyab0987
@tayyab0987 Жыл бұрын
@@kartashuvit4971 have a for loop checking for the error then kill the http request
@ronny584
@ronny584 9 ай бұрын
A video that is 8 minutes long with a trash thumbnail, ends up with a trash example. This channel is cooked lmao.
@devfortunato
@devfortunato 6 ай бұрын
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.
@BanAaron
@BanAaron Жыл бұрын
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 Жыл бұрын
Laptop speakers? Gotta get that upgraded player!
@rafaelacioly3252
@rafaelacioly3252 Жыл бұрын
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 Жыл бұрын
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.
@emil_l889
@emil_l889 Жыл бұрын
Context is really cool actually, good stuff
@a_storyy_teller
@a_storyy_teller 9 ай бұрын
your explanation is awesome bro
@MelkeyDev
@MelkeyDev 9 ай бұрын
Thank you so much 😀
@JohnBrosan
@JohnBrosan Жыл бұрын
Great video! Any chance you can provide something on Authentication/Authorization with Go? Thanks!
@wsollers1
@wsollers1 Жыл бұрын
Nice video. Simple to the point
@sjc5
@sjc5 9 ай бұрын
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 9 ай бұрын
Thanks for the feedback - Will do this for my next tutorial :)
@notoriouslycuriouswombat
@notoriouslycuriouswombat Жыл бұрын
MELKEY MELKEY MELKEY
@emil_l889
@emil_l889 Жыл бұрын
Only context go needs is enums, sadge
@johnpeterson8493
@johnpeterson8493 Жыл бұрын
how far are you in Berserk?
@MelkeyDev
@MelkeyDev Жыл бұрын
All caught up again
@thewhiteoaktree
@thewhiteoaktree Жыл бұрын
How do I get the values of an associative array in PHP?
@bumpy_lumps
@bumpy_lumps Жыл бұрын
i think it's in the go docs somewhere
@loohbiidloo4753
@loohbiidloo4753 Жыл бұрын
arr[“key” => “value”] $value = arr[“key”]
@ed223-p5g
@ed223-p5g Жыл бұрын
fix the audio pls
@rosehogenson1398
@rosehogenson1398 Жыл бұрын
Great examples as always, Melkey
@emil_l889
@emil_l889 Жыл бұрын
Used my actual userID😮
@jeffreysmith9837
@jeffreysmith9837 6 ай бұрын
this is not it. your time.Sleep() is blocking
@AnilGupta-v1c
@AnilGupta-v1c Ай бұрын
It's wrong example the sleep call is blocking call so it will still wait and just return deadline error after waiting for sleep time so the whole purpose of using context is defeated @MelkeyDev should correct the video or atleast delete the video so that your viewers are not mis-guided
@MelkeyDev
@MelkeyDev Ай бұрын
I have another video where I explain Go Context and makes the correction
How To Use The Context Package In Golang?
17:03
Anthony GG
Рет қаралды 66 М.
THIS is the BEST Way to Write HTTP Services in Golang
13:53
This Game Is Wild...
00:19
MrBeast
Рет қаралды 133 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Can You Find Hulk's True Love? Real vs Fake Girlfriend Challenge | Roblox 3D
00:24
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 12 МЛН
This is the BEST Golang Context Package Tutorial
12:18
Melkey
Рет қаралды 14 М.
GitHub Copilot Just Destroyed All AI Code Editor Startups
7:04
Advanced Golang: Channels, Context and Interfaces Explained
22:17
Code With Ryan
Рет қаралды 125 М.
Understanding Contexts in Go in 5(-ish?) Minutes
15:14
TutorialEdge
Рет қаралды 65 М.
Is Golang Still a Successful Programming Language?
14:41
Melkey
Рет қаралды 10 М.
This Is The BEST Way To Structure Your GO Projects
11:08
Melkey
Рет қаралды 81 М.
Go Pointers: When & How To Use Them Efficiently
14:09
Anthony GG
Рет қаралды 85 М.
Улучшил свой айфон!
0:17
По ту сторону Гугла
Рет қаралды 4,8 МЛН
ИГРОВОЙ ПК от ИЛОНА МАСКА, Распаковка
32:50
Making iPhone16 pink📱
0:34
Juno Craft 주노 크래프트
Рет қаралды 26 МЛН
«Осень». Самая большая загадка Windows XP
14:36
Девять десятых
Рет қаралды 1,3 МЛН
Today's Console Pick 🔥
0:11
Gleb POV
Рет қаралды 924 М.
Introducing the "VitaWear SmartBand," a next-generation wearable gadget
0:25
The Kaushal Official
Рет қаралды 1,6 МЛН
Introducing the "VitaWear SmartBand," a next-generation wearable gadget🎉
0:18
Vrashika Rajput Official
Рет қаралды 7 МЛН