Make the subscription::channel function take a FnOnce non Sync closure #1917
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.
This gives the user more flexibility on the implementation of the closure passed into the
subscription::channel
function. Specifically, it allows astd::sync::mpsc::Sender<T>
(and other non-Sync types) to be passed into the closure without requiring it to be cloned inside the normal closure but outside the async closure. Also it allows it to be aSender
instead of aSyncSender
.For example this code compiles with this patch but not without it. Without this patch I have to use a
SyncSender
(or tokio) and make another clone of the sender inside the normal closure but outside the async closure like this.hecrj, you may remember seeing similar code before. This is slightly modified from this discord question.
Please note: I'm new to the iced code base and still learning about concurrency in rust. I'm going by intuition and the compiler saying this works. So I realize there may be reasons this should not be done.