forked from Code-Sharp/WampSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility for caller proxy to return an observable
When subscribed to it will call a progressive RPC Code-Sharp#238
- Loading branch information
Johan 't Hart
committed
Mar 2, 2021
1 parent
82a672e
commit 77226d9
Showing
4 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/netstandard/WampSharp/WAMP2/V2/Api/CalleeProxy/ObservableCalleeProxyInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using System.Reflection; | ||
|
||
namespace WampSharp.V2.CalleeProxy | ||
{ | ||
internal class ObservableCalleeProxyInterceptor<T> : CalleeProxyInterceptorBase<T> | ||
{ | ||
public ObservableCalleeProxyInterceptor(MethodInfo method, IWampCalleeProxyInvocationHandler handler, ICalleeProxyInterceptor interceptor) : base(method, handler, interceptor) | ||
{ | ||
} | ||
|
||
public override object Invoke(MethodInfo method, object[] arguments) | ||
{ | ||
return Observable.Create<T>(async (obs, cancellationToken) => | ||
{ | ||
try | ||
{ | ||
var last = await Handler.InvokeProgressiveAsync | ||
(Interceptor, method, Extractor, arguments, obs.ToProgress(), cancellationToken); | ||
if (last != null) | ||
obs.OnNext(last); | ||
obs.OnCompleted(); | ||
} | ||
catch (Exception e) | ||
{ | ||
obs.OnError(e); | ||
} | ||
}); | ||
} | ||
} | ||
} |