1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-23 00:28:48 +00:00

Call ConfigureAwait(false) for all awaited tasks

This commit is contained in:
Oliver Booth 2022-11-29 19:02:13 +00:00
parent 7fe303c4eb
commit 66fe507b8d
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
6 changed files with 39 additions and 39 deletions

View File

@ -1,4 +1,4 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using VpSharp.Extensions; using VpSharp.Extensions;
using VpSharp.Internal; using VpSharp.Internal;
@ -334,7 +334,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
if (isSelf && isNewWorld) if (isSelf && isNewWorld)
{ {
await _client.EnterAsync(world); await _client.EnterAsync(world).ConfigureAwait(false);
} }
nint handle = _client.NativeInstanceHandle; nint handle = _client.NativeInstanceHandle;
@ -343,7 +343,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
{ {
if (!string.IsNullOrWhiteSpace(world)) if (!string.IsNullOrWhiteSpace(world))
{ {
await _client.EnterAsync(world); await _client.EnterAsync(world).ConfigureAwait(false);
} }
// state change self // state change self

View File

@ -150,7 +150,7 @@ public sealed class VirtualParadiseUser : IEquatable<VirtualParadiseUser>
vp_invite(_client.NativeInstanceHandle, Id, world, x, y, z, (float) yaw, (float) pitch); vp_invite(_client.NativeInstanceHandle, Id, world, x, y, z, (float) yaw, (float) pitch);
} }
ReasonCode reason = await taskCompletionSource.Task; ReasonCode reason = await taskCompletionSource.Task.ConfigureAwait(false);
return reason switch return reason switch
{ {
ReasonCode.Success => InviteResponse.Accepted, ReasonCode.Success => InviteResponse.Accepted,
@ -194,7 +194,7 @@ public sealed class VirtualParadiseUser : IEquatable<VirtualParadiseUser>
taskCompletionSource = _client.AddJoinCompletionSource(reference); taskCompletionSource = _client.AddJoinCompletionSource(reference);
} }
ReasonCode reason = await taskCompletionSource.Task; ReasonCode reason = await taskCompletionSource.Task.ConfigureAwait(false);
Location? location = null; Location? location = null;
if (reason == ReasonCode.Success) if (reason == ReasonCode.Success)
@ -217,13 +217,13 @@ public sealed class VirtualParadiseUser : IEquatable<VirtualParadiseUser>
var position = new Vector3d(x, y, z); var position = new Vector3d(x, y, z);
var rotation = Quaternion.CreateFromYawPitchRoll(yaw, pitch, 0); var rotation = Quaternion.CreateFromYawPitchRoll(yaw, pitch, 0);
VirtualParadiseWorld world = (await _client.GetWorldAsync(worldName))!; VirtualParadiseWorld world = (await _client.GetWorldAsync(worldName).ConfigureAwait(false))!;
location = new Location(world, position, rotation); location = new Location(world, position, rotation);
if (!suppressTeleport) if (!suppressTeleport)
{ {
await avatar.TeleportAsync(location.Value); await avatar.TeleportAsync(location.Value).ConfigureAwait(false);
} }
} }

View File

@ -126,7 +126,7 @@ public sealed class VirtualParadiseWorld : IEquatable<VirtualParadiseWorld>
ArgumentNullException.ThrowIfNull(action); ArgumentNullException.ThrowIfNull(action);
var builder = new WorldSettingsBuilder(_client); var builder = new WorldSettingsBuilder(_client);
await Task.Run(() => action(builder)); await Task.Run(() => action(builder)).ConfigureAwait(false);
builder.SendChanges(); builder.SendChanges();
} }

View File

@ -91,7 +91,7 @@ public sealed partial class VirtualParadiseClient
{ {
VirtualParadiseAvatar avatar = ExtractAvatar(sender); VirtualParadiseAvatar avatar = ExtractAvatar(sender);
avatar = AddOrUpdateAvatar(avatar); avatar = AddOrUpdateAvatar(avatar);
avatar.User = await GetUserAsync(vp_int(sender, IntegerAttribute.UserId)); avatar.User = await GetUserAsync(vp_int(sender, IntegerAttribute.UserId)).ConfigureAwait(false);
var args = new AvatarJoinedEventArgs(avatar); var args = new AvatarJoinedEventArgs(avatar);
RaiseEvent(AvatarJoined, args); RaiseEvent(AvatarJoined, args);
@ -165,7 +165,7 @@ public sealed partial class VirtualParadiseClient
session = vp_int(sender, IntegerAttribute.AvatarSession); session = vp_int(sender, IntegerAttribute.AvatarSession);
} }
VirtualParadiseObject? virtualParadiseObject = await ExtractObjectAsync(sender); VirtualParadiseObject? virtualParadiseObject = await ExtractObjectAsync(sender).ConfigureAwait(false);
var cell = virtualParadiseObject.Location.Cell; var cell = virtualParadiseObject.Location.Cell;
virtualParadiseObject = AddOrUpdateObject(virtualParadiseObject); virtualParadiseObject = AddOrUpdateObject(virtualParadiseObject);
@ -174,7 +174,7 @@ public sealed partial class VirtualParadiseClient
{ {
if (_cellChannels.TryGetValue(cell, out Channel<VirtualParadiseObject>? channel)) if (_cellChannels.TryGetValue(cell, out Channel<VirtualParadiseObject>? channel))
{ {
await channel.Writer.WriteAsync(virtualParadiseObject); await channel.Writer.WriteAsync(virtualParadiseObject).ConfigureAwait(false);
} }
} }
else else
@ -202,7 +202,7 @@ public sealed partial class VirtualParadiseClient
if (_objects.TryGetValue(objectId, out VirtualParadiseObject? virtualParadiseObject)) if (_objects.TryGetValue(objectId, out VirtualParadiseObject? virtualParadiseObject))
{ {
cachedObject = await ExtractObjectAsync(sender); // data discarded, but used to pull type cachedObject = await ExtractObjectAsync(sender).ConfigureAwait(false); // data discarded, but used to pull type
cachedObject.ExtractFromOther(virtualParadiseObject); cachedObject.ExtractFromOther(virtualParadiseObject);
virtualParadiseObject.ExtractFromInstance(sender); // update existing instance virtualParadiseObject.ExtractFromInstance(sender); // update existing instance
@ -233,7 +233,7 @@ public sealed partial class VirtualParadiseClient
try try
{ {
virtualParadiseObject = await GetObjectAsync(objectId); virtualParadiseObject = await GetObjectAsync(objectId).ConfigureAwait(false);
} }
catch // any exception: we don't care about GetObject failing. ID is always available catch // any exception: we don't care about GetObject failing. ID is always available
{ {
@ -264,7 +264,7 @@ public sealed partial class VirtualParadiseClient
} }
VirtualParadiseAvatar? avatar = GetAvatar(session); VirtualParadiseAvatar? avatar = GetAvatar(session);
var virtualParadiseObject = await GetObjectAsync(objectId); var virtualParadiseObject = await GetObjectAsync(objectId).ConfigureAwait(false);
var args = new ObjectClickedEventArgs(avatar, virtualParadiseObject, clickPoint); var args = new ObjectClickedEventArgs(avatar, virtualParadiseObject, clickPoint);
RaiseEvent(ObjectClicked, args); RaiseEvent(ObjectClicked, args);
} }
@ -288,7 +288,7 @@ public sealed partial class VirtualParadiseClient
if (_worldListChannel is not null) if (_worldListChannel is not null)
{ {
await _worldListChannel.Writer.WriteAsync(world); await _worldListChannel.Writer.WriteAsync(world).ConfigureAwait(false);
} }
} }
@ -316,7 +316,7 @@ public sealed partial class VirtualParadiseClient
userId = vp_int(sender, IntegerAttribute.FriendUserId); userId = vp_int(sender, IntegerAttribute.FriendUserId);
} }
VirtualParadiseUser? user = await GetUserAsync(userId); VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false);
_friends.AddOrUpdate(userId, user, (_, _) => user); _friends.AddOrUpdate(userId, user, (_, _) => user);
} }
@ -438,7 +438,7 @@ public sealed partial class VirtualParadiseClient
worldName = vp_string(sender, StringAttribute.TeleportWorld); worldName = vp_string(sender, StringAttribute.TeleportWorld);
} }
VirtualParadiseWorld? world = string.IsNullOrWhiteSpace(worldName) ? CurrentWorld : await GetWorldAsync(worldName); VirtualParadiseWorld? world = string.IsNullOrWhiteSpace(worldName) ? CurrentWorld : await GetWorldAsync(worldName).ConfigureAwait(false);
var location = new Location(world, position, rotation); var location = new Location(world, position, rotation);
VirtualParadiseAvatar? avatar = GetAvatar(session); VirtualParadiseAvatar? avatar = GetAvatar(session);
@ -458,7 +458,7 @@ public sealed partial class VirtualParadiseClient
} }
VirtualParadiseAvatar? avatar = GetAvatar(session); VirtualParadiseAvatar? avatar = GetAvatar(session);
var vpObject = await GetObjectAsync(objectId); var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false);
var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.End); var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.End);
RaiseEvent(ObjectBump, args); RaiseEvent(ObjectBump, args);
@ -500,7 +500,7 @@ public sealed partial class VirtualParadiseClient
} }
VirtualParadiseAvatar? avatar = GetAvatar(session); VirtualParadiseAvatar? avatar = GetAvatar(session);
var vpObject = await GetObjectAsync(objectId); var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false);
var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.Begin); var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.Begin);
RaiseEvent(ObjectBump, args); RaiseEvent(ObjectBump, args);
@ -519,7 +519,7 @@ public sealed partial class VirtualParadiseClient
name = vp_string(NativeInstanceHandle, StringAttribute.JoinName); name = vp_string(NativeInstanceHandle, StringAttribute.JoinName);
} }
VirtualParadiseUser? user = await GetUserAsync(userId); VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false);
var joinRequest = new JoinRequest(this, requestId, name, user); var joinRequest = new JoinRequest(this, requestId, name, user);
var args = new JoinRequestReceivedEventArgs(joinRequest); var args = new JoinRequestReceivedEventArgs(joinRequest);
RaiseEvent(JoinRequestReceived, args); RaiseEvent(JoinRequestReceived, args);
@ -553,8 +553,8 @@ public sealed partial class VirtualParadiseClient
worldName = vp_string(sender, StringAttribute.InviteWorld); worldName = vp_string(sender, StringAttribute.InviteWorld);
} }
VirtualParadiseWorld? world = await GetWorldAsync(worldName); VirtualParadiseWorld? world = await GetWorldAsync(worldName).ConfigureAwait(false);
VirtualParadiseUser? user = await GetUserAsync(userId); VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false);
var location = new Location(world, position, rotation); var location = new Location(world, position, rotation);
var request = new InviteRequest(this, requestId, avatarName, user, location); var request = new InviteRequest(this, requestId, avatarName, user, location);

View File

@ -25,7 +25,7 @@ public sealed partial class VirtualParadiseClient
if (_usersCompletionSources.TryGetValue(userId, out TaskCompletionSource<VirtualParadiseUser>? taskCompletionSource)) if (_usersCompletionSources.TryGetValue(userId, out TaskCompletionSource<VirtualParadiseUser>? taskCompletionSource))
{ {
return await taskCompletionSource.Task; return await taskCompletionSource.Task.ConfigureAwait(false);
} }
taskCompletionSource = new TaskCompletionSource<VirtualParadiseUser>(); taskCompletionSource = new TaskCompletionSource<VirtualParadiseUser>();
@ -36,7 +36,7 @@ public sealed partial class VirtualParadiseClient
vp_user_attributes_by_id(NativeInstanceHandle, userId); vp_user_attributes_by_id(NativeInstanceHandle, userId);
} }
user = await taskCompletionSource.Task; user = await taskCompletionSource.Task.ConfigureAwait(false);
user = AddOrUpdateUser(user); user = AddOrUpdateUser(user);
_usersCompletionSources.TryRemove(userId, out TaskCompletionSource<VirtualParadiseUser>? _); _usersCompletionSources.TryRemove(userId, out TaskCompletionSource<VirtualParadiseUser>? _);

View File

@ -115,7 +115,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
} }
} }
reason = await _connectCompletionSource.Task; reason = await _connectCompletionSource.Task.ConfigureAwait(false);
NoSuccess: NoSuccess:
switch (reason) switch (reason)
@ -187,8 +187,8 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task<VirtualParadiseWorld> EnterAsync(string worldName, Vector3d position) public async Task<VirtualParadiseWorld> EnterAsync(string worldName, Vector3d position)
{ {
await EnterAsync(worldName); await EnterAsync(worldName).ConfigureAwait(false);
await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity); await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity).ConfigureAwait(false);
return CurrentWorld!; return CurrentWorld!;
} }
@ -207,8 +207,8 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task<VirtualParadiseWorld> EnterAsync(string worldName, Vector3d position, Quaternion rotation) public async Task<VirtualParadiseWorld> EnterAsync(string worldName, Vector3d position, Quaternion rotation)
{ {
await EnterAsync(worldName); await EnterAsync(worldName).ConfigureAwait(false);
await CurrentAvatar!.TeleportAsync(position, rotation); await CurrentAvatar!.TeleportAsync(position, rotation).ConfigureAwait(false);
return CurrentWorld!; return CurrentWorld!;
} }
@ -226,8 +226,8 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position) public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position)
{ {
await EnterAsync(world); await EnterAsync(world).ConfigureAwait(false);
await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity); await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity).ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -245,8 +245,8 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation) public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation)
{ {
await EnterAsync(world); await EnterAsync(world).ConfigureAwait(false);
await CurrentAvatar!.TeleportAsync(position, rotation); await CurrentAvatar!.TeleportAsync(position, rotation).ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -263,7 +263,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
public async Task EnterAsync(VirtualParadiseWorld world) public async Task EnterAsync(VirtualParadiseWorld world)
{ {
ArgumentNullException.ThrowIfNull(world); ArgumentNullException.ThrowIfNull(world);
await EnterAsync(world.Name); await EnterAsync(world.Name).ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -305,7 +305,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
} }
} }
reason = await _enterCompletionSource.Task; reason = await _enterCompletionSource.Task.ConfigureAwait(false);
NoSuccess: NoSuccess:
switch (reason) switch (reason)
@ -341,9 +341,9 @@ public sealed partial class VirtualParadiseClient : IDisposable
size = vp_int(NativeInstanceHandle, IntegerAttribute.WorldSize); size = vp_int(NativeInstanceHandle, IntegerAttribute.WorldSize);
} }
await _worldSettingsCompletionSource.Task; await _worldSettingsCompletionSource.Task.ConfigureAwait(false);
VirtualParadiseWorld? world = await GetWorldAsync(worldName); VirtualParadiseWorld? world = await GetWorldAsync(worldName).ConfigureAwait(false);
if (world is null) if (world is null)
{ {
// we entered the world but it wasn't listed. unlisted world. we'll try our best to create details for it // we entered the world but it wasn't listed. unlisted world. we'll try our best to create details for it
@ -496,7 +496,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
} }
} }
reason = await _loginCompletionSource.Task; reason = await _loginCompletionSource.Task.ConfigureAwait(false);
NoSuccess: NoSuccess:
switch (reason) switch (reason)
{ {
@ -520,7 +520,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
userId = vp_int(NativeInstanceHandle, IntegerAttribute.MyUserId); userId = vp_int(NativeInstanceHandle, IntegerAttribute.MyUserId);
} }
CurrentUser = await GetUserAsync(userId); CurrentUser = await GetUserAsync(userId).ConfigureAwait(false);
vp_friends_get(NativeInstanceHandle); vp_friends_get(NativeInstanceHandle);
} }