github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/context_lagacy.go (about)

     1  //go:build !go1.20
     2  
     3  package common
     4  
     5  import "context"
     6  
     7  type ContextCancelCauseFunc func(cause error)
     8  
     9  func ContextWithCancelCause(parentContext context.Context) (context.Context, ContextCancelCauseFunc) {
    10  	ctx, cancel := context.WithCancel(parentContext)
    11  	return ctx, func(_ error) { cancel() }
    12  }
    13  
    14  func ContextCause(context context.Context) error {
    15  	return context.Err()
    16  }