Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values

5548
16
159
07.05.2021
Mario Carrion

Mario Carrion

322558
7500
95
01.07.2007
US
Описание видео:

Welcome! Let's learn and talk about the context package, specifically about how to implement deadlines, cancellation and request-scoped values using the functions defined in the package: * context.WithDeadline and context.WithTimeout * context.WithCancel and * context.WithValues The code is available here: 🤍github.com/MarioCarrion/videos/tree/563b41660420a5e77d25157f1d4798f343d12d22/2021/05/07 * Blog: 🤍mariocarrion.com/2021/05/31/learning-golang-context-package.html - * Previous Episode: "Golang Microservices: Events and Background Jobs using RabbitMQ": 🤍youtu.be/L0yJxCKrkIY * Playlist "Building Microservices in Go/Golang": 🤍🤍youtube.com/playlist?list=PL7yAAGMOat_Fn8sAXIk0WyBfK_sT1pohu * Playlist "Golang Tools and Packages": 🤍🤍youtube.com/playlist?list=PL7yAAGMOat_HEEOvH99agDs_5g51A0Ls3 * Playlist "Testing in Go": 🤍🤍youtube.com/playlist?list=PL7yAAGMOat_HSeW4zF0uRL9EaHadE4ZZq 00:00 Intro 00:56 What is the context package? 01:19 Context Deadlines 04:06 Cancellation Signals 07:32 Request-scoped values 10:02 Best practices 11:17 Parting words - Who am I: Hello👋🏼! I'm Mario, a Hands-on Software Architect and Lead Backend Engineer with more than 16 years of professional experience building all kinds of software including on-premise Industrial Automation Systems, Linux Accessibility Desktop and Browser Components as well as Distributed Advertising Microservices. Every week I will share with you different topics I've learned while working for small startups and large companies including the processes I've followed over the years for successfully delivering complex enterprise systems from start to end. Subscribe if you like Software Development, Software Architecture and Systems Design! Keep it up. Don't give up! #golang #microservices #programming - Our affiliate links below Shop our favorite products → 🤍🤍amazon.com/shop/rubycarrion Vlogging setup → 🤍rubycarrion.com/camerasforvlogging/ Get a 30 day FREE trial of Epidemic Sound → 🤍🤍epidemicsound.com/referral/szx441/ Try Amazon Prime 30-Day FREE trial → 🤍amzn.to/3s0el1R I love getting Cash Back and think you will too! Join for free and get $20 when you spend $20 → 🤍🤍rakuten.com/r/RUBYRA132?eeid=28187 Sign up to start using vidIQ to grow your YouTube channel for FREE → 🤍vidiq.com/rubycarrion - Our Vlog Channel 🤍🤍youtube.com/c/RubyCarrion/videos

Кадры из видео
Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values
Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values
Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values
Learning Golang: Context package: Cancellations, Deadlines and Request-scoped values
Тэги из видео
Комментарии пользователей:
Robert McCabe
2022-08-30 22:05:26

I like your examples. They are very clear and to the point.

Alejandro Fernández
2022-07-26 01:43:49

Amigo sos argentino? tu inglés me suena muy argentino jajaj

Renato Spakauskas
2022-03-07 22:49:15

Thank you for this class. Finally I understood what context is and how to work with them. No, it is not dark sorcery...

Ngọc Trung
2021-12-26 07:31:16

the video image is too poor, you need to fix it more

Hasan A Yousef
2021-12-13 11:32:32

Great, a side question, what is the theme you are using at your terminal?

Hector Clara
2021-11-10 14:43:26

Hola Mario,

Thanks for making such great videos, they have helped me in my current job with working with golang. I come from JS / Ruby land and typed languages can be quite confusing but I see the appeal. Your videos are great for me personally and I have learned a lot and applied it to my career. It's really great to see someone who has such passion for their work, I hope to be like that one day, since I'm pretty junior, I admire those who can "think quickly" and come up with solutions, I hope to be that kind of person one day.

SirRFI
2021-05-07 16:53:01

Do you have to use select-case syntax for this, or are there other options?
Here's an example I have in mind: func main creates context with deadline, like in the example, then creates anonymous function (which does some job, for example waits 1 second) and calls it with goroutine, then blocks at ctx.Done() (assuming it's blocking operation), waiting for deadline (for example 2 seconds). How can I make the anonymous function mark that the task has been completed? Should I call cancel()? What happens to the "defer cancel()" in such scenario?

SirRFI
2021-05-07 16:34:02

I think that the explanation for WithDeadline and WithTimeout in the example is overlapping (if that is proper term) - you showed how it works, but not what is the difference. The documentation says "WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).", and the way I understand is:
WithDeadline asks you for absolute timestamp when it should expire. It can be expressed as "it should be done by 2021-05-10" (specific date). It can be also calculated off something, like relatively to current time - "if it's not done in 10 minutes, I am leaving".
WithTimeout is abstraction or wrapper for WithDeadline, which covers common scenario of setting the deadline from current time, so you don't have to do "time.Now().Add(duration)" every time by hand - you only say how much time you are giving it (the "if it's not done in 10 minutes, I am leaving" scenario).
Is this correct?

Что ищут прямо сейчас
ο EV6 life of moses bangla apollo solo review iphone vs carro overlap shrink machine brasileirão eddie pepperrell Isslam Looping GIFs phone hacking 纪实 mages guild GERD liquid manure ch341a CHINESE CUISINE 명작 big engine swap sefo sanki ben amk
Похожие видео
26.09.2021
Advanced Golang: Channels, Context and Interfaces Explained

Advanced Golang: Channels, Context and Interfaces Explained

31.03.2017
justforfunc #9: The Context Package

justforfunc #9: The Context Package

19.11.2021
Learning Golang: Relational Databases - Introduction to database/sql

Learning Golang: Relational Databases - Introduction to database/sql

04.03.2018
Concurrency in Go

Concurrency in Go

03.09.2021
Learning Golang: Concurrency Patterns using errgroup package

Learning Golang: Concurrency Patterns using errgroup package

05.12.2021
Understanding Contexts in Go in 5(-ish?) Minutes

Understanding Contexts in Go in 5(-ish?) Minutes

12.08.2021
Learning Golang: Introduction to Concurrency Patterns, goroutines and channels

Learning Golang: Introduction to Concurrency Patterns, goroutines and channels

24.04.2021
Why should you use/learn Golang? (As a Hiring Manager, as an Individual Contributor)

Why should you use/learn Golang? (As a Hiring Manager, as an Individual Contributor)

29.07.2020
Writing idiomatic Go using Domain Driven Design, Damiano Petrungaro

Writing idiomatic Go using Domain Driven Design, Damiano Petrungaro

03.02.2022
gRPC vs GraphQL vs REST? What's the best API Technology for Golang?

gRPC vs GraphQL vs REST? What's the best API Technology for Golang?

10.06.2022
Software Architecture in Golang: Orchestrator Pattern

Software Architecture in Golang: Orchestrator Pattern

28.05.2021
Golang Microservices: Pub/Sub with Redis as Message Broker

Golang Microservices: Pub/Sub with Redis as Message Broker

09.01.2021
Go Class: 25 Context

Go Class: 25 Context

30.08.2020
The mysteries of the Go Context package REVEALED!

The mysteries of the Go Context package REVEALED!

14.03.2013
The first 20 hours -- how to learn anything | Josh Kaufman | TEDxCSU

The first 20 hours -- how to learn anything | Josh Kaufman | TEDxCSU

04.12.2021
Learning Golang: Introduction to Benchmarks

Learning Golang: Introduction to Benchmarks