mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Context #24

Open mtchuyen opened 2 years ago

mtchuyen commented 2 years ago

Context Goroutines and mutex error because sending a copy of counter to the anonymous

https://groups.google.com/g/golang-nuts/c/TK4v1pegaXg

mtchuyen commented 2 years ago

Why you should be using errgroup.WithContext() in your Golang server handlers

https://www.fullstory.com/blog/why-errgroup-withcontext-in-golang-server-handlers/

mtchuyen commented 1 year ago

Using Context in Golang - Cancellation, Timeouts and Values (With Examples)

https://www.sohamkamani.com/golang/context-cancellation-and-values/

Context-less Go — Writing HTTP Services Easily

https://betterprogramming.pub/context-less-go-854db3e5510

mtchuyen commented 1 year ago

Để hiểu được Context, trước hết phải hiểu được 2 khái niệm

Đọc sơ lược ở đây: Ref3: Understanding the context package in golang

Ở 2 phần đầu (Goroutine & Channels) thể hiện các nhược điểm khi triển khai

Context giúp tăng cường cho app khi muốn dùng cả Goroutine & Channels.

Trong phần Example của [Ref3] mô tả chi tiết 1 chương trình sử dụng context, có sử dụng context.WithTimeout nên sẽ xem lại ví dụ này sau.

https://viblo.asia/p/golang-context-cancel-va-cach-su-dung-gGJ59rVDKX2

https://viblo.asia/p/golang-context-deadline-va-timeout-la-gi-XL6lAejrlek

https://betterprogramming.pub/how-and-when-to-use-context-in-go-b365ddf42ae2

Phần dịch khá sát với tài liệu gốc (https://go.dev/blog/context):

mtchuyen commented 1 year ago