Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go context package #254

Open
eubnara opened this issue Dec 25, 2021 · 1 comment
Open

go context package #254

eubnara opened this issue Dec 25, 2021 · 1 comment
Labels

Comments

@eubnara
Copy link
Owner

eubnara commented Dec 25, 2021

https://www.youtube.com/watch?v=LSzR0VEraWw
https://go.dev/blog/context

  1. Cancellation
    • When a request is cancelled or timed out, all goroutines working on that request should exit quickly and so the system can reclaim any resources they are using.
    • select 구문에서 ctx.Done() 를 이용하여 context 가 취소되거나 타임아웃 됐을 때 backend 작업들을(database or RPC) 기다리지 않고 끊어버릴 수 있다.
  2. Propagation
    • 같은 request 안에서 전달해야할 정보들을 넣어 공유할 수 있다.
    • Decorate 패턴으로 값을 넣는 방법 예시: https://youtu.be/LSzR0VEraWw?t=1792
    • context.WithValue() 를 이용할 때 키가 충돌될 것 같다면 패키지에서 타입을 지정하고 export 를 하지 않도록 하면 충돌을 회피할 수 있다.: https://youtu.be/LSzR0VEraWw?t=1939
@eubnara eubnara added the GO label Dec 25, 2021
@eubnara
Copy link
Owner Author

eubnara commented Jan 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant