KDOC 332: Contextのテストを読むと理解しやすい
この文書のステータス
- 作成
- 2025-02-17 貴島
- レビュー
- 2025-02-17 貴島
概要
Contextは使い方を理解するのが難しい。Go本体のソースコードにあるテストが、使い方を端的に示していてわかりやすかった。例えを使って長々と説明するよりもミニマルなコード例を示してくれたほうがわかりやすいことがある。
https://github.com/kd-collective/go/blob/19e923182e590ae6568c2c714f20f32512aeb3e3/src/context/context_test.go#L200-L205
ctx, _ := WithCancel(Background()) checkChildren("after creation", ctx, 0) _, cancel := WithCancel(ctx) checkChildren("with WithCancel child ", ctx, 1) cancel() checkChildren("after canceling WithCancel child", ctx, 0)
関連
なし。