Skip to content

Commit

Permalink
fix(storage): Make the AsyncOperation ID really unique
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Oct 9, 2020
1 parent 0d8fe25 commit c65e55e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Uno.Foundation/AsyncOperation.TResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ internal class AsyncOperation<TResult> : IAsyncOperation<TResult>, IAsyncOperati
public static AsyncOperation<TResult> FromTask(FuncAsync<AsyncOperation<TResult>, TResult> builder)
=> new AsyncOperation<TResult>(builder);

private static long _nextId;

private readonly CancellationTokenSource _cts = new CancellationTokenSource();
private AsyncOperationCompletedHandler<TResult>? _onCompleted;
private AsyncStatus _status;
Expand Down Expand Up @@ -58,7 +56,7 @@ public AsyncOperationCompletedHandler<TResult>? Completed
}
}

public uint Id { get; } = (uint)Interlocked.Increment(ref _nextId);
public uint Id { get; } = AsyncOperation.CreateId();

public Task<TResult> Task { get; }

Expand Down
4 changes: 4 additions & 0 deletions src/Uno.Foundation/AsyncOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace Windows.Foundation
{
internal static class AsyncOperation
{
private static long _nextId;
internal static uint CreateId()
=> (uint)Interlocked.Increment(ref _nextId);

public static AsyncOperation<TResult> FromTask<TResult>(Func<CancellationToken, Task<TResult>> builder)
=> new AsyncOperation<TResult>((ct, _) => builder(ct));
}
Expand Down

0 comments on commit c65e55e

Please sign in to comment.