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

Move EnumerateWorldsAsync to Worlds partial

This commit is contained in:
Oliver Booth 2022-11-30 18:56:33 +00:00
parent c2748567fc
commit 9f16e6cc77
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 22 additions and 20 deletions

View File

@ -1,15 +1,37 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading.Channels; using System.Threading.Channels;
using VpSharp.Entities; using VpSharp.Entities;
using static VpSharp.Internal.Native;
namespace VpSharp; namespace VpSharp;
public sealed partial class VirtualParadiseClient public sealed partial class VirtualParadiseClient
{ {
private readonly ConcurrentDictionary<string, string> _worldSettings = new(); private readonly ConcurrentDictionary<string, string> _worldSettings = new();
private readonly ConcurrentDictionary<string, VirtualParadiseWorld> _worlds = new();
private Channel<VirtualParadiseWorld>? _worldListChannel = Channel.CreateUnbounded<VirtualParadiseWorld>(); private Channel<VirtualParadiseWorld>? _worldListChannel = Channel.CreateUnbounded<VirtualParadiseWorld>();
private TaskCompletionSource _worldSettingsCompletionSource = new(); private TaskCompletionSource _worldSettingsCompletionSource = new();
/// <summary>
/// Gets an enumerable of the worlds returned by the universe server.
/// </summary>
/// <returns>An <see cref="IAsyncEnumerable{T}" /> containing <see cref="VirtualParadiseWorld" /> values.</returns>
/// <remarks>
/// This method will yield results back as they are received from the world server. To access a consumed collection,
/// use <see cref="GetWorldsAsync" />.
/// </remarks>
/// <seealso cref="GetWorldsAsync" />
public IAsyncEnumerable<VirtualParadiseWorld> EnumerateWorldsAsync()
{
_worldListChannel = Channel.CreateUnbounded<VirtualParadiseWorld>();
lock (Lock)
{
_ = vp_world_list(NativeInstanceHandle, 0);
}
return _worldListChannel.Reader.ReadAllAsync();
}
/// <summary> /// <summary>
/// Gets a world by its name. /// Gets a world by its name.
/// </summary> /// </summary>

View File

@ -402,26 +402,6 @@ public sealed partial class VirtualParadiseClient : IDisposable
return CurrentWorld!; return CurrentWorld!;
} }
/// <summary>
/// Gets an enumerable of the worlds returned by the universe server.
/// </summary>
/// <returns>An <see cref="IAsyncEnumerable{T}" /> containing <see cref="VirtualParadiseWorld" /> values.</returns>
/// <remarks>
/// This method will yield results back as they are received from the world server. To access a consumed collection,
/// use <see cref="GetWorldsAsync" />.
/// </remarks>
/// <seealso cref="GetWorldsAsync" />
public IAsyncEnumerable<VirtualParadiseWorld> EnumerateWorldsAsync()
{
_worldListChannel = Channel.CreateUnbounded<VirtualParadiseWorld>();
lock (Lock)
{
vp_world_list(NativeInstanceHandle, 0);
}
return _worldListChannel.Reader.ReadAllAsync();
}
/// <summary> /// <summary>
/// Leaves the current world. /// Leaves the current world.
/// </summary> /// </summary>