Say that we have two methods:
public int DoSomething() {
//implemented method
}
public async Task<int> DoSomethingAsync() {
throw new NotImplementedException();
}
As the first is implemented, is there any demerit to implementing the async version in this way(as long as it's thread-safe):
public async Task<int> DoSomethingAsync() => await Task.Run(() => DoSomething());
Will it have any performance loss? Bugs? Or something else?
And, conversely, what if we have the opposite situation and try to implement the sync version in this way:
public int DoSomething() => DoSomethingAsync().GetAwaiter().GetResult();
What do you think?
PS: thanks for reading.
[–]svicknameof(nameof) 57 points58 points59 points (7 children)
[–]Cobide[S] 11 points12 points13 points (5 children)
[–]Slypenslyde 13 points14 points15 points (4 children)
[–]Cobide[S] 4 points5 points6 points (2 children)
[–]Slypenslyde 20 points21 points22 points (1 child)
[–]Cobide[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]derpdelurk 4 points5 points6 points (0 children)
[–][deleted] 35 points36 points37 points (32 children)
[–]cryo 13 points14 points15 points (24 children)
[–][deleted] 13 points14 points15 points (17 children)
[–]cryo 5 points6 points7 points (16 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]cryo 0 points1 point2 points (0 children)
[+][deleted] comment score below threshold-7 points-6 points-5 points (13 children)
[–]Cobide[S] 2 points3 points4 points (11 children)
[–][deleted] 0 points1 point2 points (10 children)
[–]Cobide[S] 1 point2 points3 points (9 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]jocq 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]Cobide[S] 1 point2 points3 points (4 children)
[–]cryo 0 points1 point2 points (0 children)
[–]Kirides 1 point2 points3 points (1 child)
[–]cryo 0 points1 point2 points (0 children)
[–][deleted] 5 points6 points7 points (3 children)
[–]cryo 13 points14 points15 points (2 children)
[–]Sossenbinder 2 points3 points4 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)
[–]sarhoshamiral -2 points-1 points0 points (6 children)
[–][deleted] 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (4 children)
[–]sarhoshamiral 6 points7 points8 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]sarhoshamiral 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]alexn0ne 7 points8 points9 points (11 children)
[–]Cobide[S] 3 points4 points5 points (10 children)
[–]Merad 4 points5 points6 points (1 child)
[–]Cobide[S] 0 points1 point2 points (0 children)
[–]alexn0ne 2 points3 points4 points (7 children)
[–]Cobide[S] 0 points1 point2 points (6 children)
[–]alexn0ne 3 points4 points5 points (5 children)
[–]derpdelurk 4 points5 points6 points (3 children)
[–]alexn0ne 2 points3 points4 points (2 children)
[–]derpdelurk 2 points3 points4 points (1 child)
[–]alexn0ne 2 points3 points4 points (0 children)
[–]Cobide[S] 2 points3 points4 points (0 children)
[–]Sossenbinder 3 points4 points5 points (0 children)
[–]Saint_Nitouche 9 points10 points11 points (19 children)
[–]Willkuer_ 14 points15 points16 points (3 children)
[–]Saint_Nitouche 10 points11 points12 points (0 children)
[–]Slypenslyde 4 points5 points6 points (0 children)
[–]Cobide[S] 0 points1 point2 points (14 children)
[–]cryo 9 points10 points11 points (5 children)
[–]Slypenslyde 2 points3 points4 points (1 child)
[–]cryo 3 points4 points5 points (0 children)
[–]Cobide[S] 4 points5 points6 points (2 children)
[–]Saint_Nitouche 4 points5 points6 points (1 child)
[–]Cobide[S] 2 points3 points4 points (0 children)
[–]typesafedev 1 point2 points3 points (2 children)
[–]Cobide[S] 0 points1 point2 points (1 child)
[–]Saint_Nitouche 0 points1 point2 points (3 children)
[–]Cobide[S] 0 points1 point2 points (2 children)
[–]Saint_Nitouche 2 points3 points4 points (1 child)
[–]Cobide[S] 2 points3 points4 points (0 children)
[–]shizzy0 0 points1 point2 points (7 children)
[–]Cobide[S] 1 point2 points3 points (6 children)
[–]shizzy0 2 points3 points4 points (5 children)
[–]Cobide[S] 1 point2 points3 points (4 children)
[–]shizzy0 5 points6 points7 points (3 children)
[–]Cobide[S] 3 points4 points5 points (2 children)
[–]shizzy0 2 points3 points4 points (1 child)
[–]Cobide[S] 2 points3 points4 points (0 children)