Skip to content

Commit

Permalink
Avoid blocking in WampClientSubject
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Zelingher committed Oct 11, 2014
1 parent 0ae214d commit a8aadc6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/net45/WampSharp/WAMP2/V2/Api/Rx/WampClientSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,28 @@ public IDisposable Subscribe(IObserver<IWampSerializedEvent> observer)
{
Task<IDisposable> task = mTopic.Subscribe(new RawTopicClientSubscriber(observer), new SubscribeOptions());

// TODO: think of a better solution
task.Wait();
FutureDisposable result = new FutureDisposable(task);

return task.Result;
return result;
}

private class FutureDisposable : IDisposable
{
private readonly Task<IDisposable> mDisposableTask;

public FutureDisposable(Task<IDisposable> disposableTask)
{
mDisposableTask = disposableTask;
}

public void Dispose()
{
if (mDisposableTask.IsCompleted)
{
IDisposable result = mDisposableTask.Result;
result.Dispose();
}
}
}
}
}
Expand Down

0 comments on commit a8aadc6

Please sign in to comment.