Skip to content

LK4D4/joincontext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

joincontext

Build Status GoDoc

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.

For additional info see godoc page

Example

	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

About

Join contexts like never before!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages