package jsonrpc

import "context"

type clientContextKey struct{}

// ClientFromContext retrieves the client from the context, if any. This can be used to perform
// 'reverse calls' in a handler method.
func ContextWithConn(ctx context.Context, c Conn) context.Context {
	return context.WithValue(ctx, clientContextKey{}, c)
}

// ClientFromContext retrieves the client from the context, if any. This can be used to perform
// 'reverse calls' in a handler method.
func ConnFromContext(ctx context.Context) (Conn, bool) {
	client, ok := ctx.Value(clientContextKey{}).(Conn)
	return client, ok
}