I’ve written a RPC function that I call from the Unity SDK that simply pings the server to see if it’s online and the player is authenticated. Can somebody show me how to modify the following code to apply a 5 second time out ? Will the catch statement be called when it times out ?
@Spuddy There’s another function parameter you can pass into all the functions in the SDK which is named canceller and expects a CancellationToken. This is how you can provide a maximum time for the function to execute for.
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
m_Client.RpcAsync(mysession, "ping", "", canceller: cts.Token);
// Will throw a TaskCancelledException if a timeout occurs.
All of this is standard .NET functionality and not Unity engine specific:
I’ve tried what you said and created a CancellationToken with a time out of 2 seconds and also set a timeout of 10 seconds on the Nakama client but it’s taking around 75 seconds to throw the exception so I don’t understand what’s going on ? I’ve tested in the Unity Editor on a Mac but haven’t tried on a device yet
Update: It seems to time out after the expected 2 seconds on my iPad, just takes over a minute in the Unity Editor