feat: Add Send bounds to AsyncNetworkClient (fixes #542) #757
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey Devolutions team,
First off, thanks so much for creating IronRDP! It's been incredibly useful, and I really appreciate the work you've put into it.
I wanted to propose a change that addresses issue #542 and enables using the
AsyncNetworkClient
more effectively in multithreaded applications, based on my experience building a Tauri app.Motivation & Problem (#542):
As discussed in #542, the original
AsyncNetworkClient
lackedSend
bounds. This prevented it from being used directly within spawned asynchronous tasks (e.g., usingtokio::spawn
). I encountered this exact limitation while building a Tauri application where I need to manage multiple simultaneous RDP connections, each running in its own Tokio task. For this to work safely, the client and its future need to beSend
.Solution:
To resolve #542 and support my use case, I've implemented a two-part solution:
Send
Bounds toAsyncNetworkClient
: I've added the necessarySend
bounds to the main trait. This directly fixes the issue reported in error: future cannot be sent between threads safely #542 and allows the client to be used safely across threads in environments like Tokio.WasmAsyncNetworkClient
: Simply addingSend
bounds would break compatibility with WASM environments, as WASM is single-threaded and its associated types often don't implementSend
. To prevent this regression, I've created a parallel traitWasmAsyncNetworkClient
specifically for WASM, which is identical but omits theSend
requirements.Validation:
This dual-trait setup is currently working successfully in my Tauri application. It allows me to spawn multiple RDP connection tasks using
tokio::spawn
(thanks to theSend
bounds onAsyncNetworkClient
), while separate WASM builds usingWasmAsyncNetworkClient
continue to compile and function correctly.Proposal:
This approach directly solves the core problem of #542 by enabling thread-safe multithreaded usage, while carefully preserving WASM compatibility via the separate trait. I believe this makes the library more robust and versatile for different deployment targets.
Happy to discuss this further! Let me know your thoughts.