Obsolete messages explain CancellationToken change by idg10 · Pull Request #2286 · dotnet/reactive (original) (raw)

Resolves #2284

As #2283 reported, there is a trap waiting for those who were using the Await forms available for various operators in Ix.NET's LINQ to IAsyncEnumerable<T> (System.Linq.Async) when they upgrade to the .NET runtime library implementation (System.Linq.AsyncEnumerable).

Our preview builds provide Obsolete attributes explaining that you need to move from, e.g., SelectAwait to Select, but the message did not mention that you will also need to change the callback signature. Whereas Ix.NET's implementation allowed you to pass a callback that does not take a cancellation token (and cancellation was available through methods with a completely different name such as SelectAwaitWithCancellation), the .NET runtime's implementation requires async callbacks to accept a CancellationToken.

So something like this:

someAsyncEnum.SelectAwait(async x => await Something(x))

needs two changes:

  1. replace SelectAwait with Select
  2. add a second argument to the callback to receive the CancellationToken

So at a minimum, that means something like this:

someAsyncEnum.Select(async (x, _) => await Something(x))

That need to add the extra parameter to accept the CancellationToken was not obvious.

This modifies the Obsolete attributes to include instructions to this effect.