Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the subscription::channel function take a FnOnce non Sync closure #1917

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

JonathanLindsey
Copy link
Contributor

This gives the user more flexibility on the implementation of the closure passed into the subscription::channel function. Specifically, it allows a std::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 a Sender instead of a SyncSender.

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.

… of a Fn closure and remove Sync as a requirement for its output.
@JonathanLindsey JonathanLindsey changed the title Make the subscription::channel function take a FnOnce closure instead… Make the subscription::channel function take a FnOnce non Sync closure Jun 16, 2023
@hecrj hecrj added improvement An internal improvement shell labels Jun 16, 2023
@hecrj hecrj added this to the 0.10.0 milestone Jun 16, 2023
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thanks 🙇

@hecrj hecrj enabled auto-merge June 16, 2023 13:58
@hecrj hecrj merged commit e7e2b7b into iced-rs:master Jun 16, 2023
9 checks passed
@JonathanLindsey JonathanLindsey deleted the subscription_channel_FnOnce branch June 16, 2023 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement An internal improvement shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants