Skip to content

Commit

Permalink
Refactor receive logic
Browse files Browse the repository at this point in the history
References #21
  • Loading branch information
andreashuber-lawo committed Apr 26, 2016
1 parent b18891d commit 8bce51e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Lawo.EmberPlusSharp/Model/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ private async void ReceiveLoop()
{
while (true)
{
await this.WaitForAndApplyProviderChangesAsync();
await this.WaitForProviderChangesAsync();
this.ApplyProviderChanges();
await this.RetrieveChildrenAsync();
}
}
Expand Down Expand Up @@ -352,20 +353,24 @@ private async Task RetrieveChildrenCoreAsync()
{
while (await this.SendRequestAsync())
{
await this.WaitForAndApplyProviderChangesAsync();
await this.WaitForProviderChangesAsync();
this.ApplyProviderChanges();
}
}

private async Task WaitForAndApplyProviderChangesAsync()
private void ApplyProviderChanges()
{
await this.receiveQueue.WaitForMessageAsync();

while (this.receiveQueue.MessageCount > 0)
{
this.ApplyChange(this.receiveQueue.DequeueMessage());
}
}

private Task WaitForProviderChangesAsync()
{
return this.receiveQueue.WaitForMessageAsync();
}

private void OnConnectionLost(object sender, ConnectionLostEventArgs e)
{
var handler = this.ConnectionLost;
Expand Down

0 comments on commit 8bce51e

Please sign in to comment.