@@ -19,6 +19,8 @@ public abstract class RustBridgeCommunicator : IRustBridgeCommunicator
1919 protected IntPtr _walletHandle ;
2020
2121 protected StringBuilder _eventErrorBuffer ;
22+ private static SemaphoreSlim _semaphore = new SemaphoreSlim ( 1 ) ;
23+
2224 public RustBridgeCommunicator ( )
2325 {
2426 _messageReceivedCallback = WalletMessageReceivedCallback ;
@@ -37,18 +39,15 @@ public RustBridgeCommunicator(IntPtr walletHandle)
3739
3840 public void WalletEventsReceivedCallback ( string message , string error , IntPtr context )
3941 {
40- dynamic parsedJson = JsonConvert . DeserializeObject ( message ) ;
41- string s = JsonConvert . SerializeObject ( parsedJson , Formatting . Indented ) ;
42- Console . WriteLine ( s ) ;
4342 IWalletEvent ? walletEvent = JsonConvert . DeserializeObject < WalletEvent > ( message ) ;
4443 WalletEventReceived ? . Invoke ( this , walletEvent ) ;
4544 }
4645
4746 public void WalletMessageReceivedCallback ( string message , string error , IntPtr context )
4847 {
49- bool isSuccess = String . IsNullOrEmpty ( error ) && ! message . Contains ( @"{""type"":""error" ) ;
48+ bool isSuccess = string . IsNullOrEmpty ( error ) && ! message . Contains ( @"{""type"":""error" ) ;
5049
51- string messageToSignal = String . IsNullOrEmpty ( error ) ? message : error ;
50+ string messageToSignal = string . IsNullOrEmpty ( error ) ? message : error ;
5251
5352 if ( _messageReceivedCallbackSetResult != null )
5453 _messageReceivedCallbackSetResult ( new RustBridgeGenericResponse ( messageToSignal , isSuccess ) ) ;
@@ -62,6 +61,7 @@ public void WalletMessageReceivedCallback(string message, string error, IntPtr c
6261 /// <returns></returns>
6362 public async Task < RustBridgeGenericResponse > SendMessageAsync ( string message )
6463 {
64+ await _semaphore . WaitAsync ( ) ;
6565
6666 TaskCompletionSource < RustBridgeGenericResponse > ? taskCompletionSource =
6767 new TaskCompletionSource < RustBridgeGenericResponse > ( ) ;
@@ -75,7 +75,11 @@ await Task.Factory.StartNew(() =>
7575 } , TaskCreationOptions . AttachedToParent ) ;
7676
7777
78- return await task ;
78+ RustBridgeGenericResponse genericResponse = await task ;
79+
80+ _semaphore . Release ( ) ;
81+
82+ return genericResponse ;
7983 }
8084
8185 public void SubscribeToEvents ( WalletEventTypes walletEventTypes )
0 commit comments