1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-10 17:36:19 +00:00

added sub/unsub methods, added waiting for id event

This commit is contained in:
Jan Korf 2018-11-26 07:22:01 +01:00
parent b1085bc764
commit 5645e8e7f3
3 changed files with 24 additions and 0 deletions

View File

@ -155,6 +155,22 @@ namespace CryptoExchange.Net
socket.Send(data);
}
public virtual async Task Unsubscribe(UpdateSubscription sub)
{
await sub.Close();
}
public virtual async Task UnsubscribeAll()
{
await Task.Run(() =>
{
var tasks = new List<Task>();
foreach (var sub in new List<SocketSubscription>(sockets))
tasks.Add(sub.Close());
Task.WaitAll(tasks.ToArray());
});
}
public override void Dispose()
{
lock(sockets)

View File

@ -6,6 +6,7 @@ namespace CryptoExchange.Net.Sockets
public class SocketEvent
{
public string Name { get; set; }
public int Id { get; set; }
private CallResult<bool> result;
private ManualResetEvent setEvnt;

View File

@ -64,6 +64,13 @@ namespace CryptoExchange.Net.Sockets
return Events.Single(e => e.Name == name).Wait();
}
public CallResult<bool> WaitForEvent(string name, int id)
{
var evnt = Events.Single(e => e.Name == name);
evnt.Id = id;
return evnt.Wait();
}
public async Task Close()
{
Socket.ShouldReconnect = false;