Skip to content

Add Task::blocking helper#3389

Open
edwloef wants to merge 1 commit into
iced-rs:masterfrom
edwloef:task-blocking
Open

Add Task::blocking helper#3389
edwloef wants to merge 1 commit into
iced-rs:masterfrom
edwloef:task-blocking

Conversation

@edwloef

@edwloef edwloef commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

... and replace usages of task::blocking and task::try_blocking.

The semantics of task::blocking and task::try_blocking weren't entirely clear without reading the function bodies themselves, since they provided the blocking closure with an async channel that you can only try_send on. Most uses only send one item, which is fine since the channel has capacity 1, but sending multiple items can lead to encountering a full channel, which you can't do anything useful about in a blocking context. In the one case where that was necessary (devtools comet installation) silently dropping the message in such situations is probably okay though.

Now, when it's just one item, we can just use the return value of that closure. When it's not, the user can move a sender into the closure and batch with the receiver, so they can choose whether to use an unbounded channel, a bounded channel with potential message loss, or a channel supporting both blocking send and async recv (e.g. tokio, smol, ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant