How to: RPC that starts a background process that times out in 15 seconds if nothing else happens?

Question in title

we want the RPC to return immediately but start a background process that times out in 15s or something if it doesn’t finish otherwise

Hi @aamistak. What sort of use case do you have for when you’d want to execute a background process from an RPC function that must complete after some time?

Hi @novabyte! We’d like to enforce a timeout on our matchmaker tickets (e.g. if after 90s no match has been found then force a match with any available players). We couldn’t find any built-in support for that so our next hope was that we’d be able to start a new concurrent “background timeout” that would do something clever with the ticket if it still exists after the timeout’s elapsed.

For what it’s worth, we know you would recommend having the clients manage this. We’re asking if it’s possible to do this type of functionality at all on the server.

(we’ve got this implemented on the client right now and have no end to the number of edge cases we’re hitting, our clients are generally a little to unreliable in terms of connectivity and window focus for it to be tenable)

(we’ve got this implemented on the client right now and have no end to the number of edge cases we’re hitting, our clients are generally a little to unreliable in terms of connectivity and window focus for it to be tenable)

@bfops If this is purely for matchmaking: the matchmaking ticket automatically expires and the matchmaking request is removed from the pool once the user disconnects.

Not sure why you are getting edge cases with connectivity.

We’re enforcing a timer for each player to play his turn, so I’d also like to know what’s the suggested method.

We’re keeping a tick counter and incrementing it in each match_loop but I hope there’s a better way :b

The tick counter is the right approach here. It’s the only logical clock that can be used. This is what we suggest in authoritative match handlers too.

1 Like

Our use case doesn’t necessarily want to remove players from matchmaking if they disconnect (e.g. short disconnections).

Either way does nakama have server-side functionality for enforcing ticket expiry or is it meant to be implemented purely on the client?

Our use case doesn’t necessarily want to remove players from matchmaking if they disconnect (e.g. short disconnections).

No - this is a built-in server behaviour that cannot (and won’t) change. If a player leaves, the server cleans up all the resources including their matchmaking requests that is left in the matchmaking pool.

Either way does nakama have server-side functionality for enforcing ticket expiry or is it meant to be implemented purely on the client?

Currently no functionality exists on the server-side. This is supposed to be client-driven and cannot be server-driven.

If this was possible, what should be the behaviour if the server creates a matchmaking request, but at some later point, when the matchmake is completed, the client(s) had gone away?