Skip to content

Commit

Permalink
Added MessagesQueueCount property to client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Noman Musleh committed Dec 24, 2021
1 parent 1090e39 commit aa28039
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OpenAPI.Net/OpenAPI.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageTags>cTrader, Open API, Spotware</PackageTags>
<Description>A .NET RX library for Spotware Open API</Description>
<PackageId>Spotware.OpenAPI.Net</PackageId>
<Version>1.3.2</Version>
<Version>1.3.3</Version>
<Platforms>AnyCPU</Platforms>
<Company>Spotware</Company>
<Authors>Spotware</Authors>
Expand Down
11 changes: 11 additions & 0 deletions src/OpenAPI.Net/OpenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public OpenClient(string host, int port, TimeSpan heartbeatInerval, int maxReque
/// </summary>
public DateTimeOffset LastSentMessageTime { get; private set; }

/// <summary>
/// The count of messages on queue to be sent
/// </summary>
public int MessagesQueueCount { get; private set; }

/// <summary>
/// Connects to the API based on you specified method (websocket or TCP)
/// </summary>
Expand Down Expand Up @@ -235,6 +240,8 @@ public async Task SendMessage<T>(T message, ProtoOAPayloadType payloadType, stri
/// <returns>Task</returns>
public async Task SendMessage(ProtoMessage message)
{
MessagesQueueCount += 1;

await _messagesChannel.Writer.WriteAsync(message);
}

Expand Down Expand Up @@ -293,6 +300,8 @@ private async Task StartSendingMessages(CancellationToken cancellationToken)
}

await SendMessageInstant(message);

if (MessagesQueueCount > 0) MessagesQueueCount -= 1;
}
}
}
Expand Down Expand Up @@ -321,6 +330,8 @@ public void Dispose()

_messagesChannel.Writer.TryComplete();

MessagesQueueCount = 0;

if (UseWebSocket)
{
_webSocketMessageReceivedDisposable?.Dispose();
Expand Down

0 comments on commit aa28039

Please sign in to comment.