-
I have a subscription such as type Subscription {
message: String!
} in func (r *subscriptionResolver) Message(ctx context.Context) (<-chan string, error) {
subscriber := pubsub.Subscribe("subject", ...)
// store subscriber in context
} Now I want to store that "pubsub subscriber" in context, so I can h.AddTransport(transport.Websocket{
KeepAlivePingInterval: 10 * time.Second,
CloseFunc: func(ctx context.Context, closeCode int) {
pubsubSubsriber, _ := ctx.Get("subscriber")
handle := pubsubSubsriber.(*pubsub.Sub)
handle.Unsubscribe()
},
}) question is how to store that object in context in Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Here is an example of how i handle that: This part handles the initialization of subscription and closing This part handles notifying everyone subscribed for those events Example usage of notifying for changes Example usage of subscribing |
Beta Was this translation helpful? Give feedback.
Here is an example of how i handle that:
This part handles the initialization of subscription and closing
https://github.com/UnAfraid/wg-ui/blob/master/api/subscription/user_service.go#L37-L56
This part handles notifying everyone subscribed for those events
https://github.com/UnAfraid/wg-ui/blob/master/api/subscription/user_service.go#L25-L35
Example usage of notifying for changes
https://github.com/UnAfraid/wg-ui/blob/master/api/mutation_resolver_create_user.go
Example usage of subscribing
https://github.com/UnAfraid/wg-ui/blob/master/api/subscription_resolver.go#L13-L15