CancellationTokenSource

Hello!

I noticed in the latest Unity Nakama CancellationTokenSource is not optional any more since it’s Token is called straight away even though further down the line it’s allowed to be nullable. This creates all sorts of problems and backward compatibility issues which of course are easily solved but I was wondering whether this was missed or intentional.

( an example is JoinGroupAsync )

Thanks!

Hi @terahardstudios we changed CancellationTokenSource to CancellationToken to allow the same token to be used around our user’s codebase. It should still be optional.

I don’t see where it was changed as the signature is still:

public Task JoinGroupAsync(
      ISession session,
      string groupId,
      RetryConfiguration retryConfiguration,
      CancellationTokenSource canceller)

unless you mean this one ( which I just found ):

public async Task JoinGroupAsync(
      ISession session,
      string groupId,
      RetryConfiguration retryConfiguration = null,
      CancellationToken canceller = default (CancellationToken))

I can’t see because it’s inside the dll but I think the new version is calling JoinGroupAsync for example cancellationTokenSource.Token so if cancellationTokenSource is null it throws an error of null reference and using default(CancellationTokenSource) doesn’t work either so I am forced to do in my own methods:

public async Task<bool> JoinClanAsync(
			string groupId,
			RetryConfiguration retryConfiguration = null,
			CancellationTokenSource canceller = null )

if( canceller == null )
{
	canceller = new CancellationTokenSource();
}

So I guess I should use the new method instead?

I’m not quite following you. Pass a CancellationToken to Nakama now instead of CancellationTokenSource. How you want to handle the upstream changes is up to you.

basically I hadn’t seen the new overloaded method, all good. thanks!