Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Fix bug where subscribe event is sent twice.
Browse files Browse the repository at this point in the history
Caused by reconnect behavior wherein it reconnects to the previous
channels, and the fact that the ConnectAsync() method did not wait for
the connection established event to be raised.

Solved by simply having ConnectAsync() wait for the connection
established event.
  • Loading branch information
vegardlarsen committed Jan 18, 2014
1 parent 4831347 commit ef4c711
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Pusher/Pusher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public async Task ConnectAsync()
ApplicationKey)));
_connection.OnData += ReceivedEvent;
await _connection.Open();

// wait for the connection established event before returning
var completionSource = new TaskCompletionSource<string>();
GenericEventEmittedHandler<ConnectionEstablishedEventArgs> eventHandler =
(sender, e) => completionSource.SetResult(e.DataObject.SocketId);
GetEventSubscription<ConnectionEstablishedEventArgs>().EventEmitted += eventHandler;
await completionSource.Task;
GetEventSubscription<ConnectionEstablishedEventArgs>().EventEmitted -= eventHandler;
}

public void AddContract(IEventContract contract)
Expand Down

0 comments on commit ef4c711

Please sign in to comment.