mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-10 05:15:42 +00:00
Move EnumerateWorldsAsync to Worlds partial
This commit is contained in:
parent
c2748567fc
commit
9f16e6cc77
@ -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>
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user