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

**URL:** <https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191>\
**Category:** Local Setup\
**Created:** [September 3, 2019, 11:59pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191 "2019-09-03T23:59:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aamistak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/aamistak/32/66_2.png) [@aamistak](https://forum.heroiclabs.com/u/aamistak)\
**Post date:** [September 3, 2019, 11:59pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/1 "2019-09-03T23:59:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [September 4, 2019, 4:36pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/2 "2019-09-04T16:36:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bfops](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bfops/32/73_2.png) [@bfops](https://forum.heroiclabs.com/u/bfops)\
**Post date:** [September 4, 2019, 4:57pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/3 "2019-09-04T16:57:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aamistak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/aamistak/32/66_2.png) [@aamistak](https://forum.heroiclabs.com/u/aamistak)\
**Post date:** [September 4, 2019, 5:49pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/4 "2019-09-04T17:49:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bfops](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bfops/32/73_2.png) [@bfops](https://forum.heroiclabs.com/u/bfops)\
**Post date:** [September 4, 2019, 6:24pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/5 "2019-09-04T18:24:34Z")

</div>

(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)

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [September 5, 2019, 5:53am UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/6 "2019-09-05T05:53:17Z")

</div>

> (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.

---

<div class="post-metadata">

**Author:** ![GroovyAntoidDev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/groovyantoiddev/32/39_2.png) [@GroovyAntoidDev](https://forum.heroiclabs.com/u/GroovyAntoidDev)\
**Post date:** [September 5, 2019, 8:20am UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/7 "2019-09-05T08:20:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [September 5, 2019, 8:21am UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/8 "2019-09-05T08:21:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bfops](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bfops/32/73_2.png) [@bfops](https://forum.heroiclabs.com/u/bfops)\
**Post date:** [September 8, 2019, 3:57pm UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/9 "2019-09-08T15:57:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [September 9, 2019, 6:46am UTC](https://forum.heroiclabs.com/t/how-to-rpc-that-starts-a-background-process-that-times-out-in-15-seconds-if-nothing-else-happens/191/10 "2019-09-09T06:46:29Z")

</div>

> 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?
