Hello,
Is it possible to queue stuff for processing later which can be picked by the server?
Here’s an example flow:
- Players fight vs each other.
- Match ends, now I want to increase their level, check their quest completion etc.
- So I add it to a queue which can be processed by the server when possible.
This helps me not delay the response after the match ends as well as prevents processing of all heavy actions at once.
Regards
Update: I learnt about Events but it seems to be Go only. I guess I’ll just emit an event after a match and then process the required data.
Hello @sesposito, I was just attempting to do this. How do i access the nk
object while processing an event? Seems like it doesn’t accept this parameter, I need to emit a notification after processing.
You can use a closure to pass the nk module to the function:
func processEvent(nk runtime.NakamaModule) func(context.Context, runtime.Logger, *api.Event) {
return func(ctx context.Context, logger runtime.Logger, evt *api.Event) {
switch evt.GetName() {
case "account_updated":
logger.Debug("process evt: %+v", evt)
// Send event to an analytics service.
default:
logger.Error("unrecognised evt: %+v", evt)
}
}
}
// InitModule
if err := initializer.RegisterEvent(processEvent(nk)); err != nil {
return err
}
1 Like