golang.tokyo#5でのLT資料です。
2016 07 11 When it’s released later this month, Go 1.7 will move the x/net/context package to the stdlib, as plain old context. It also attaches a context object to net/http.Requests, and gives you a few helper methods. Dedicated Gophers are probably already familiar with the great introductory blog article by Sameer Ajmani, Go Concurrency Patterns: Context, published all the way back in 2014. If
はい、というわけで、前記事のworkerパターンをcontextつかったらどーなるか、についてです。 前の記事や、その元記事のソースを読んでいる前提ですので、未読の方はそちらの確認からお願いします。 さて、ざっくりとした変更の方針ですけど、以下の2点です。 contextを使うことで、workerの実装側でキャンセルできるようにする workerに渡す値はcontext経由にする。 というのをヤッツケでやってつくってみました。 以下変更点の解説です。 まず、元実装ではworkerで実行される処理がベタ書きだったのを汎用化するため、dispatcherのqueueに入れるjobをとqueueの定義を変更します。 type ( job struct { proc func(context.Context) ctx context.Context } Dispatcher struct { qu
基本的なアイデアは、タスクを、 type ContextErrFunc func(ctx context.Context) error という型に統一して、シリアルに実行する、並列に実行する、というのを組み合わせることができるようにする。 package flow import "golang.org/x/net/context" // ContextErrFunc : 処理共通化のためのタスクの定義用 type ContextErrFunc func(ctx context.Context) error // ContextSerial : ContextErrFunc を直列に実行して、エラーが途中で起こったらその時点でエラーを返す func ContextSerial(fs ...ContextErrFunc) ContextErrFunc { return func(ctx con
The approaches in this post are now obsolete thanks to Go 1.7, which adds the context package to the standard library and uses it in the net/http *http.Request type. The background info here may still be helpful, but I wrote a follow-up post that revisits things for Go 1.7 and beyond. The golang.org/x/net/context package (hereafter referred as net/context although it’s not yet in the standard libr
Go1.7ではgolang.org/x/net/contextがcontextパッケージとして標準パッケージに仲間入りする.そしていくつかの標準パッケージではcontextパッケージを使ったメソッド/関数も新たに登場する.contextパッケージは今後さらに重要な,Gopherは普通に扱うべき,パッケージになると考えられる.本記事ではそもそもcontextパッケージとは何か?なぜ登場したのか?なぜ重要なのか?どのように使うべきか?についてまとめる. contextパッケージが初めて紹介されたのは2014年のThe Go Blogの記事 “Go Concurrency Patterns: Context”である.この記事ではなぜGoogleがcontextパッケージを開発したのか,どのように使うのか具体的な検索タスクを例に解説されている.まだ読んだことがない人はそちらを先に読むと良い. co
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く