Documentation ¶
Overview ¶
Package joincontext provides a way to combine two contexts. For example it might be useful for grpc server to cancel all handlers in addition to provided handler context.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Join ¶
Join returns new context which is child for two passed contexts. It starts new goroutine which tracks both contexts.
Done() channel is closed when one of parents contexts is done.
Deadline() returns earliest deadline between parent contexts.
Err() returns error from first done parent context.
Value(key) looks for key in parent contexts. First found is returned.
Example ¶
package main import ( "fmt" "time" "github.com/LK4D4/joincontext" "golang.org/x/net/context" ) func main() { ctx1, cancel1 := context.WithCancel(context.Background()) defer cancel1() ctx2 := context.Background() ctx, cancel := joincontext.Join(ctx1, ctx2) defer cancel() select { case <-ctx.Done(): default: fmt.Println("context alive") } cancel1() // give some time to propagate time.Sleep(100 * time.Millisecond) select { case <-ctx.Done(): fmt.Println(ctx.Err()) default: } }
Output: context alive context canceled
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.