mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
a3980c2308
Co-authored-by: Rene Jochum <rene@jochum.dev>
30 lines
490 B
Go
30 lines
490 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
type serverKey struct{}
|
|
type wgKey struct{}
|
|
|
|
func wait(ctx context.Context) *sync.WaitGroup {
|
|
if ctx == nil {
|
|
return nil
|
|
}
|
|
wg, ok := ctx.Value(wgKey{}).(*sync.WaitGroup)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return wg
|
|
}
|
|
|
|
func FromContext(ctx context.Context) (Server, bool) {
|
|
c, ok := ctx.Value(serverKey{}).(Server)
|
|
return c, ok
|
|
}
|
|
|
|
func NewContext(ctx context.Context, s Server) context.Context {
|
|
return context.WithValue(ctx, serverKey{}, s)
|
|
}
|