-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
OnConnected
is called with a copied context.
- Loading branch information
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
// Detach returns a context that keeps all the values of its parent context | ||
// but detaches from the cancellation and error handling. | ||
func Detach(ctx context.Context) context.Context { return detachedContext{ctx} } | ||
|
||
type detachedContext struct{ parent context.Context } | ||
|
||
func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false } | ||
func (v detachedContext) Done() <-chan struct{} { return nil } | ||
func (v detachedContext) Err() error { return nil } | ||
func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters