Skip to content

Commit

Permalink
[CS4014] warning disable - Because this call is not awaited (#6512)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaba authored Mar 13, 2023
1 parent 01345f6 commit 535072c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,13 @@ public AsyncPipeToDelayActor(string persistenceId)
{
var sender = Sender;
var self = Self;
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Run(() =>
{
Thread.Sleep(10);
return msg;
}).PipeTo(sender, self);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

await Task.Delay(3000);
});
Expand All @@ -600,12 +602,14 @@ public AsyncReentrantActor(string persistenceId)
CommandAsync<string>(async msg =>
{
var sender = Sender;
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Run(() =>
{
//Sleep to make sure the task is not completed when ContinueWith is called
Thread.Sleep(100);
return msg;
}).ContinueWith(_ => sender.Tell(msg)); // ContinueWith will schedule with the implicit ActorTaskScheduler
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

Thread.Sleep(3000);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ protected override Task DeleteAsync(SnapshotMetadata metadata)

protected override Task DeleteAsync(string persistenceId, SnapshotSelectionCriteria criteria)
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
base.DeleteAsync(persistenceId, criteria); // we actually delete it properly, but act as if it failed
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
var promise = new TaskCompletionSource<object>();
promise.SetException(new InvalidOperationException("Failed to delete snapshot for some reason."));
return promise.Task;
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka.Remote.TestKit/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ public override void ChannelInactive(IChannelHandlerContext context)
Task.Factory.StartNew(() =>
{
RemoteConnection.Shutdown(context.Channel);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
RemoteConnection.ReleaseAll(); // yep, let it run asynchronously.
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
context.FireChannelInactive();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public async Task Make_sure_async_works()
{
await _testingEventFilter.ForLogLevel(LogLevel).ExpectAsync(1, TimeSpan.FromSeconds(2), async () =>
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Delay(TimeSpan.FromMilliseconds(10)).ContinueWith(t => { LogMessage("whatever"); });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka.Tests/Actor/ActorSystemSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ public async Task AwaitTermination_after_termination_callbacks()
callbackWasRun = true;
});

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
new TaskFactory().StartNew(() =>
{
Task.Delay(Dilated(TimeSpan.FromMilliseconds(200))).Wait();
actorSystem.Terminate();
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

await actorSystem.WhenTerminated.AwaitWithTimeout(TimeSpan.FromSeconds(5));
Assert.True(callbackWasRun);
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka.Tests/Actor/Dispatch/ActorModelSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,15 @@ public async Task A_dispatcher_must_handle_queuing_from_multiple_threads()

foreach (var i in Enumerable.Range(1, 10))
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Run(() =>
{
foreach (var c in Enumerable.Range(1, 20))
{
a.Tell(new CountDown(counter));
}
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}

try
Expand Down
36 changes: 36 additions & 0 deletions src/core/Akka.Tests/Actor/PipeToSupportSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,55 +42,71 @@ public PipeToSupportSpec()
public async Task Should_immediately_PipeTo_completed_Task()
{
var task = Task.FromResult("foo");
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
task.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
await ExpectMsgAsync("foo");
}

[Fact]
public async Task ValueTask_Should_immediately_PipeTo_completed_Task()
{
var task = new ValueTask<string>("foo");
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
task.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
await ExpectMsgAsync("foo");
}

[Fact]
public async Task Should_by_default_send_task_result_as_message()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_task.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("Hello");
await ExpectMsgAsync("Hello");
}

[Fact]
public async Task ValueTask_Should_by_default_send_task_result_as_message()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTask.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("Hello");
await ExpectMsgAsync("Hello");
}

[Fact]
public async Task Should_by_default_not_send_a_success_message_if_the_task_does_not_produce_a_result()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskWithoutResult.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("Hello");
await ExpectNoMsgAsync(TimeSpan.FromMilliseconds(100));
}

[Fact]
public async Task ValueTask_Should_by_default_not_send_a_success_message_if_the_task_does_not_produce_a_result()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTaskWithoutResult.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("Hello");
await ExpectNoMsgAsync(TimeSpan.FromMilliseconds(100));
}

[Fact]
public async Task Should_by_default_send_task_exception_as_status_failure_message()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_task.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskWithoutResult.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetException(new Exception("Boom"));
await ExpectMsgAsync<Status.Failure>(x => x.Cause.Message == "Boom");
await ExpectMsgAsync<Status.Failure>(x => x.Cause.Message == "Boom");
Expand All @@ -99,8 +115,12 @@ public async Task Should_by_default_send_task_exception_as_status_failure_messag
[Fact]
public async Task ValueTask_Should_by_default_send_task_exception_as_status_failure_message()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTask.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTaskWithoutResult.PipeTo(TestActor);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetException(new Exception("Boom"));
await ExpectMsgAsync<Status.Failure>(x => x.Cause.Message == "Boom");
await ExpectMsgAsync<Status.Failure>(x => x.Cause.Message == "Boom");
Expand All @@ -109,8 +129,12 @@ public async Task ValueTask_Should_by_default_send_task_exception_as_status_fail
[Fact]
public async Task Should_use_success_handling_to_transform_task_result()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_task.PipeTo(TestActor, success: x => "Hello " + x);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskWithoutResult.PipeTo(TestActor, success: () => "Hello");
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("World");
var pipeTo = await ReceiveNAsync(2, default).Cast<string>().ToListAsync();
pipeTo.Should().Contain("Hello");
Expand All @@ -120,8 +144,12 @@ public async Task Should_use_success_handling_to_transform_task_result()
[Fact]
public async Task ValueTask_Should_use_success_handling_to_transform_task_result()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTask.PipeTo(TestActor, success: x => "Hello " + x);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTaskWithoutResult.PipeTo(TestActor, success: () => "Hello");
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetResult("World");
var pipeTo = await ReceiveNAsync(2, default).Cast<string>().ToListAsync();
pipeTo.Should().Contain("Hello");
Expand All @@ -131,8 +159,12 @@ public async Task ValueTask_Should_use_success_handling_to_transform_task_result
[Fact]
public async Task Should_use_failure_handling_to_transform_task_exception()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_task.PipeTo(TestActor, failure: e => "Such a " + e.Message);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskWithoutResult.PipeTo(TestActor, failure: e => "Such a " + e.Message);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetException(new Exception("failure..."));
await ExpectMsgAsync("Such a failure...");
await ExpectMsgAsync("Such a failure...");
Expand All @@ -141,8 +173,12 @@ public async Task Should_use_failure_handling_to_transform_task_exception()
[Fact]
public async Task ValueTask_Should_use_failure_handling_to_transform_task_exception()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTask.PipeTo(TestActor, failure: e => "Such a " + e.Message);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_valueTaskWithoutResult.PipeTo(TestActor, failure: e => "Such a " + e.Message);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_taskCompletionSource.SetException(new Exception("failure..."));
await ExpectMsgAsync("Such a failure...");
await ExpectMsgAsync("Such a failure...");
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Util/Internal/AtomicState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ public abstract Task InvokeState<TState>(TState state,
public void Enter()
{
EnterInternal();
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
NotifyTransitionListeners();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}

}
Expand Down
2 changes: 2 additions & 0 deletions src/examples/AspNetCore/Akka.AspNetCore/AkkaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public async Task StartAsync(CancellationToken cancellationToken)
//await _actorSystem.WhenTerminated.ContinueWith(tr => {
// _applicationLifetime.StopApplication();
//});
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_actorSystem.WhenTerminated.ContinueWith(tr => {
_applicationLifetime.StopApplication();
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
await Task.CompletedTask;
}

Expand Down

0 comments on commit 535072c

Please sign in to comment.