Skip to content

Commit a8aadc6

Browse files
author
Elad Zelingher
committed
Avoid blocking in WampClientSubject
1 parent 0ae214d commit a8aadc6

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/net45/WampSharp/WAMP2/V2/Api/Rx/WampClientSubject.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,28 @@ public IDisposable Subscribe(IObserver<IWampSerializedEvent> observer)
7878
{
7979
Task<IDisposable> task = mTopic.Subscribe(new RawTopicClientSubscriber(observer), new SubscribeOptions());
8080

81-
// TODO: think of a better solution
82-
task.Wait();
81+
FutureDisposable result = new FutureDisposable(task);
8382

84-
return task.Result;
83+
return result;
84+
}
85+
86+
private class FutureDisposable : IDisposable
87+
{
88+
private readonly Task<IDisposable> mDisposableTask;
89+
90+
public FutureDisposable(Task<IDisposable> disposableTask)
91+
{
92+
mDisposableTask = disposableTask;
93+
}
94+
95+
public void Dispose()
96+
{
97+
if (mDisposableTask.IsCompleted)
98+
{
99+
IDisposable result = mDisposableTask.Result;
100+
result.Dispose();
101+
}
102+
}
85103
}
86104
}
87105
}

0 commit comments

Comments
 (0)