Skip to content

Commit

Permalink
chore: Comply with CA2007
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Nov 30, 2023
1 parent 341cfe5 commit 06ea0cf
Show file tree
Hide file tree
Showing 36 changed files with 97 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,18 @@ async ValueTask<uint> LoadMore(uint desiredCount, CancellationToken ct)
{
var originalCount = currentCount;

await pageTokens.WaitFor(requests.RequestMoreItems(desiredCount), ct);
await pageTokens.WaitFor(requests.RequestMoreItems(desiredCount), ct).ConfigureAwait(false);

var resultCount = currentCount;

return (uint)Math.Max(0, resultCount - originalCount);
}

async ValueTask SetSelected(SelectionInfo info, CancellationToken ct)
=> await state.UpdateMessageAsync(msg => msg.Selected(info).Set(BindableViewModelBase.BindingSource, collection), ct);
ValueTask SetSelected(SelectionInfo info, CancellationToken ct)
=> state.UpdateMessageAsync(msg => msg.Selected(info).Set(BindableViewModelBase.BindingSource, collection), ct);

async ValueTask Edit(Func<IDifferentialCollectionNode, IDifferentialCollectionNode> change, CancellationToken ct)
=> await state.UpdateMessageAsync(
ValueTask Edit(Func<IDifferentialCollectionNode, IDifferentialCollectionNode> change, CancellationToken ct)
=> state.UpdateMessageAsync(
msg =>
{
// Note: The change might have been computed on an older version of the collection
Expand All @@ -209,6 +209,6 @@ async ValueTask Edit(Func<IDifferentialCollectionNode, IDifferentialCollectionNo
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
await _state.DisposeAsync();
await _state.DisposeAsync().ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<uint> GetLoaded()
{
try
{
return (await _result.Task).Count;
return (await _result.Task.ConfigureAwait(false)).Count;
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void Update(Func<IDifferentialCollectionNode, IDifferentialCollectionNode
var tcs = new TaskCompletionSource<object?>();
using var _ = _ct.Token.Register(() => tcs.TrySetCanceled());
dispatcher.TryEnqueue(() => tcs.TrySetResult(default));
await tcs.Task;
await Dequeue();
await tcs.Task.ConfigureAwait(false);
await Dequeue().ConfigureAwait(false);
},
_ct.Token);
}
Expand All @@ -51,12 +51,12 @@ public void Update(Func<IDifferentialCollectionNode, IDifferentialCollectionNode
private async Task Dequeue()
{
// Make sure we are not running multiple dequeue in //
using var _ = await _gate.LockAsync(_ct.Token);
using var _ = await _gate.LockAsync(_ct.Token).ConfigureAwait(false);

var editions = Interlocked.Exchange(ref _editions, ImmutableQueue<Func<IDifferentialCollectionNode, IDifferentialCollectionNode>>.Empty);
foreach (var edition in editions)
{
await _editFromView(edition, _ct.Token);
await _editFromView(edition, _ct.Token).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public async Task<uint> LoadMoreItems(uint count, CancellationToken ct)
throw new ObjectDisposedException(nameof(PaginationService));
}

using (await _gate.LockAsync(ct))
using (await _gate.LockAsync(ct).ConfigureAwait(false))
{
return await new LoadRequest(this, count).GetResult(ct);
return await new LoadRequest(this, count).GetResult(ct).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async ValueTask DisposeAsync()
switch (service)
{
case IAsyncDisposable asyncDisposable:
await asyncDisposable.DisposeAsync();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
break;

case IDisposable disposable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public async ValueTask<TResult> ExecuteAsync<TResult>(AsyncFunc<TResult> action,

TryEnqueue(Execute);

return await tcs.Task;
return await tcs.Task.ConfigureAwait(false);

async void Execute()
{
try
{
tcs.TrySetResult(await action(ct));
tcs.TrySetResult(await action(ct).ConfigureAwait(false));
}
catch (Exception error)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
root = false

[*.cs]
dotnet_diagnostic.CA2007.severity = suggestion
dotnet_diagnostic.CA2007.severity = error
dotnet_diagnostic.CA2016.severity = error
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/Core/Feed.T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Uno.Extensions.Reactive;
/// Provides a set of static methods to create and manipulate <see cref="IFeed{T}"/>.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
public static class Feed<T> // We set the T on the class to it greatly helps type inference of factory delegates
public static partial class Feed<T> // We set the T on the class to it greatly helps type inference of factory delegates
{
/// <summary>
/// Gets or create a custom feed from an async method.
Expand Down
22 changes: 14 additions & 8 deletions src/Uno.Extensions.Reactive/Core/Feed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ static IFeed<IImmutableList<TResult>> Create(IFeed<TSource> parameter, AsyncFunc
return ImmutableList<TResult>.Empty;
}

var items = await FeedExecution.Current!.GetPaginated<TResult>(
b => b
.ByIndex()
.GetPage((req, ct) => gp(value, req, ct)));
var items = await FeedExecution
.Current
!.GetPaginated<TResult>(
b => b
.ByIndex()
.GetPage((req, ct) => gp(value, req, ct)))
.ConfigureAwait(false);

return items;
});
Expand Down Expand Up @@ -280,10 +283,13 @@ static IFeed<IImmutableList<TResult>> Create(IFeed<TSource> parameter, (TCursor
return ImmutableList<TResult>.Empty;
}

var items = await FeedExecution.Current!.GetPaginated<TResult>(
b => b
.ByCursor(args.firstPage)
.GetPage((token, count, ct) => args.getPage(value, token, count, ct)));
var items = await FeedExecution
.Current
!.GetPaginated<TResult>(
b => b
.ByCursor(args.firstPage)
.GetPage((token, count, ct) => args.getPage(value, token, count, ct)))
.ConfigureAwait(false);

return items;
});
Expand Down
5 changes: 3 additions & 2 deletions src/Uno.Extensions.Reactive/Core/IFeed.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Uno.Extensions.Reactive;

/// <summary>
/// A **stateless** stream of data.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
public interface IFeed<T> : ISignal<Message<T>>
/* where T : record */
public partial interface IFeed<T> : ISignal<Message<T>>
/* where T : record or struct */
{
}
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Reactive/Core/Internal/FeedSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public async IAsyncEnumerable<Message<T>> GetMessages(SourceContext subscriberCo
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
await _context.DisposeAsync();
await _context.DisposeAsync().ConfigureAwait(false);
_requests.Dispose();
await _messages.DisposeAsync();
await _messages.DisposeAsync().ConfigureAwait(false);
}
}
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/Core/Internal/SourceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public async ValueTask DisposeAsync()

// Note: We make sure dispose only the values explicitly defined on this context,
// but not those that are inherited from the parent context.
await (_localStates?.DisposeAsync() ?? default);
await (_localStates?.DisposeAsync() ?? default).ConfigureAwait(false);
_localRequests?.Dispose();
}
catch (Exception) { }
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Reactive/Core/Internal/StateImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async ValueTask UpdateMessageAsync(Action<MessageBuilder<T>> updater, Can

var update = new Update(updater, _updatesKind);
_inner.Add(update);
await update.HasBeenApplied; // Makes sure to forward (the first) error to the caller if any.
await update.HasBeenApplied.ConfigureAwait(false); // Makes sure to forward (the first) error to the caller if any.
}

private void Enable()
Expand All @@ -144,7 +144,7 @@ public async ValueTask DisposeAsync()
// This is a temporary patch until we support dynamic updates of the subscription mode in FeedSubscription (i.e. the _subscriptionMode).
if (_subscription is { } sub)
{
await sub.DisposeAsync();
await sub.DisposeAsync().ConfigureAwait(false);
}
_subscriptionMode?.Dispose();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Extensions.Reactive/Core/ListFeed.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static async ValueTask<Option<IImmutableList<T>>> Option<T>(this IListFee
=> await FeedDependency.TryGetCurrentMessage(listFeed).ConfigureAwait(false) switch
{
{ } message => message.Current.EnsureNoError().Data,
null => await listFeed.Options(AsyncFeedValue.Default, ct).FirstOrDefaultAsync(Extensions.Option<IImmutableList<T>>.Undefined(), ct)
null => await listFeed.Options(AsyncFeedValue.Default, ct).FirstOrDefaultAsync(Extensions.Option<IImmutableList<T>>.Undefined(), ct).ConfigureAwait(false)
};

/// <summary>
Expand All @@ -96,7 +96,7 @@ public static async ValueTask<Option<IImmutableList<T>>> Option<T>(this IListFee
{
not null when kind is not AsyncFeedValue.Default => throw new NotSupportedException($"Only kind AsyncFeedValue.Default is currently supported by the dynamic feed (requested: {kind})."),
{ } message => message.Current.EnsureNoError().Data,
null => await listFeed.Options(kind, ct).FirstOrDefaultAsync(Extensions.Option<IImmutableList<T>>.Undefined(), ct)
null => await listFeed.Options(kind, ct).FirstOrDefaultAsync(Extensions.Option<IImmutableList<T>>.Undefined(), ct).ConfigureAwait(false)
};

/// <summary>
Expand Down Expand Up @@ -234,7 +234,7 @@ public static IFeed<IImmutableList<TItem>> AsFeed<TItem>(
/// <returns>The selected items, or an empty collection if none.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public static async ValueTask<IImmutableList<T>> GetSelectedItems<T>(this IListFeed<T> source, CancellationToken ct)
=> (await source.Message(ct)).Current.GetSelectedItems();
=> (await source.Message(ct).ConfigureAwait(false)).Current.GetSelectedItems();

/// <summary>
/// Gets the selected item of a list feed, or null if none.
Expand All @@ -246,5 +246,5 @@ public static async ValueTask<IImmutableList<T>> GetSelectedItems<T>(this IListF
[EditorBrowsable(EditorBrowsableState.Never)]
public static async ValueTask<T?> GetSelectedItem<T>(this IListFeed<T> source, CancellationToken ct)
where T : notnull
=> (await source.Message(ct)).Current.GetSelectedItem();
=> (await source.Message(ct).ConfigureAwait(false)).Current.GetSelectedItem();
}
8 changes: 4 additions & 4 deletions src/Uno.Extensions.Reactive/Core/ListState.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ await state.UpdateMessageAsync(msg =>
success = true;
msg.Selected(selection);
}
}, ct);
}, ct).ConfigureAwait(false);

return success;
}
Expand All @@ -255,7 +255,7 @@ await state.UpdateMessageAsync(msg =>
success = true;
msg.Selected(selection);
}
}, ct);
}, ct).ConfigureAwait(false);

return success;
}
Expand All @@ -267,9 +267,9 @@ await state.UpdateMessageAsync(msg =>
/// <param name="state">The state to update.</param>
/// <param name="ct">A token to abort the async operation.</param>
/// <returns></returns>
public static async ValueTask ClearSelectionAsync<T>(this IListState<T> state, CancellationToken ct = default)
public static ValueTask ClearSelectionAsync<T>(this IListState<T> state, CancellationToken ct = default)
where T : notnull
=> await state.UpdateMessageAsync(msg => msg.Selected(SelectionInfo.Empty), ct);
=> state.UpdateMessageAsync(msg => msg.Selected(SelectionInfo.Empty), ct);

/// <summary>
/// [DEPRECATED] Use .ClearSelectionAsync instead
Expand Down
4 changes: 3 additions & 1 deletion src/Uno.Extensions.Reactive/Operators/HotSwapFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public void Set(ISignal<Message<T>>? feed)
/// <inheritdoc />
public async IAsyncEnumerable<Message<T>> GetSource(SourceContext context, [EnumeratorCancellation] CancellationToken ct = default)
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task, false positive: it's for the DisposeAsync which cannot be configured here
await using var session = new Session(this, context, ct);
#pragma warning restore CA2007
while (await session.MoveNextAsync().ConfigureAwait(false))
{
yield return session.Current;
Expand Down Expand Up @@ -109,7 +111,7 @@ public async ValueTask<bool> MoveNextAsync()
{
var moveNext = enumerator.MoveNextAsync().AsTask();
if (await Task.WhenAny(moveNext, next.Task).ConfigureAwait(false) == moveNext
&& await moveNext)
&& await moveNext.ConfigureAwait(false))
{
var canSkip = !_isFirstMessage && _isFirstMessageOfCurrentEnumerator;

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/Operators/ListFeedSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public async ValueTask DisposeAsync()
_ct.Cancel();
if (_impl is not null)
{
await _impl.DisposeAsync();
await _impl.DisposeAsync().ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/Operators/SelectAsyncFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async void BeginEnumeration()
if (projection is not null)
{
// Make sure to await the end of the last projection before completing the subject!
await projection;
await projection.ConfigureAwait(false);
}
subject.Complete();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.Extensions.Reactive/Operators/StateForEach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private async Task Execute(T? value, CancellationToken ct)

try
{
await _action(value, ct);
await _action(value, ct).ConfigureAwait(false);
}
catch (OperationCanceledException) when (ct.IsCancellationRequested)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Reactive/Presentation/Bindings/Bindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private async void UpdateOwner(T value)
_asyncSetCt?.Cancel();
_asyncSetCt = new();

await _property.Update(_ => value, true, _asyncSetCt.Token);
await _property.Update(_ => value, true, _asyncSetCt.Token).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -247,7 +247,7 @@ private async ValueTask OnSubPropertyUpdated<TProperty>(

// 2. Propagate the update to the parent (i.e. update the backing state)
// Note: We re-invoke the 'update' delegate here (instead of using the '_value') to make sure to respect ACID
await _property.Update(t => set(t, update(get(t))), false, ct);
await _property.Update(t => set(t, update(get(t))), false, ct).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async ValueTask OnItemUpdated(Func<TItem, TItem> updater, bool isLeafPropertyCha
_owner.RaisePropertyChanged($"Item[{CurrentIndex}]");
}

await _owner._listProperty.Update(list => _owner.Replace(list, previous, updated), false, ct);
await _owner._listProperty.Update(list => _owner.Replace(list, previous, updated), false, ct).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async ValueTask Update(Func<T, T> updater, bool isLeafPropertyChanged, Ca
{
if (CanWrite)
{
await _update!(updater, isLeafPropertyChanged, ct);
await _update!(updater, isLeafPropertyChanged, ct).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async void ViewModelToView(Action<TProperty> updated)
updated(initialValue);
var ct = stateImpl.Context.Token;
var source = FeedUIHelper.GetSource(stateImpl, stateImpl.Context);
var dispatcher = await _dispatcher.GetFirstResolved(ct);
var dispatcher = await _dispatcher.GetFirstResolved(ct).ConfigureAwait(false);

dispatcher.TryEnqueue(async () =>
{
Expand Down Expand Up @@ -206,7 +206,7 @@ protected ILogger __Reactive_Log()
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
await _disposables.DisposeAsync();
await _disposables.DisposeAsync().ConfigureAwait(false);
_propertyChanged.Dispose();
_dispatcher.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public bool TryExecute(object? viewParameter, SourceContext context, Cancellatio

var completed = 0;
var task = Task.Run(
async () =>
{
using var _ = context.AsCurrent();
await _config.Execute(coercedParameter, ct);
},
ct);
async () =>
{
using var _ = context.AsCurrent();
await _config.Execute(coercedParameter, ct).ConfigureAwait(false);
},
ct);

// Note: As the CT is cancelled when the command is disposed, we have to use a registration instead of a continuation
// to make sure `ReportExecutionEnded` is run synchronously so before the EventManager is being disposed!
Expand Down
Loading

0 comments on commit 06ea0cf

Please sign in to comment.