11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Threading . Tasks ;
45using Microsoft . AspNetCore . SignalR . Client ;
@@ -38,9 +39,9 @@ public static T CreateNotInheritedHub<T>(this HubConnection hubConnection)
3839 /// <typeparam name="T">Type of client method</typeparam>
3940 /// <param name="connection">Connection to the hub that we subscribe to</param>
4041 /// <param name="action">The action that will be executed when you call the customer</param>
41- public static void Subscribe < T > ( this HubConnection connection , Action < T > action ) where T : IClientMethod
42+ public static IDisposable Subscribe < T > ( this HubConnection connection , Action < T > action ) where T : IClientMethod
4243 {
43- SubscribeNotInherited < T > ( connection , action ) ;
44+ return SubscribeNotInherited < T > ( connection , action ) ;
4445 }
4546
4647 /// <summary>
@@ -50,20 +51,22 @@ public static void Subscribe<T>(this HubConnection connection, Action<T> action)
5051 /// <typeparam name="T">Type of client method</typeparam>
5152 /// <param name="connection">Connection to the hub that we subscribe to</param>
5253 /// <param name="action">The action that will be executed when you call the customer</param>
53- public static void SubscribeNotInherited < T > ( this HubConnection connection , Action < T > action )
54+ public static IDisposable SubscribeNotInherited < T > ( this HubConnection connection , Action < T > action )
5455 {
5556 var recieveMessage = typeof ( T ) ;
5657 var methodName = recieveMessage . Name ;
5758 var paramsList = recieveMessage . GetProperties ( )
5859 . Select ( ( info ) => info . PropertyType )
5960 . ToArray ( ) ;
6061
61- connection . On ( methodName , paramsList ,
62- objects =>
63- {
64- var instance = objects . CreateInstance < T > ( ) ;
65- return Task . FromResult ( action . DynamicInvoke ( instance ) ) ;
66- } ) ;
62+ IDisposable subscription = connection . On ( methodName , paramsList , ( object [ ] args ) =>
63+ {
64+ T instance = args . CreateInstance < T > ( ) ;
65+ action ( instance ) ;
66+ return Task . CompletedTask ;
67+ } ) ;
68+
69+ return subscription ;
6770 }
6871
6972 /// <summary>
0 commit comments