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

send_future_batch requires a Vec, doesn't accept an Option #2506

Closed
1 of 3 tasks
lilyball opened this issue Mar 9, 2022 · 1 comment · Fixed by #2507
Closed
1 of 3 tasks

send_future_batch requires a Vec, doesn't accept an Option #2506

lilyball opened this issue Mar 9, 2022 · 1 comment · Fixed by #2507
Labels

Comments

@lilyball
Copy link

lilyball commented Mar 9, 2022

Problem
batch_callback() works with any result type that implements SendAsMessage, which basically means either Option or Vec. But send_future_batch() requires Vec. This feels like an unnecessary limitation, it should be able to use SendAsMessage as well so that way I can have a future that optionally sends a message.

Arguably send_message_batch() could take SendAsMessage as well for consistency, though it's less important there as I can simply choose to not send a message if I have None. If you add a batch_callback_future() (which seems like a missing hole right now) then that too should use SendAsMessage.

Environment:

  • Yew version: 0.19.3

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@WorldSEnder
Copy link
Member

WorldSEnder commented Mar 10, 2022

To explain a bit of the reasoning, send_message* are internally used as the low-level primitive that the SendAsMessage impls use.

If you have maybe_msg: Option<Message> you should be able to maybe_msg.send(&link) to achieve the same effect as explicitly pattern matching on the option and doing link.send_message(..) (with use yew::html::SendAsMessage somewhere).

I agree that batch_callback_future is a bit of a hole right now, but moreover, Callback is perhaps missing a way to construct it from an async function, without explicitly having to call spawn_local. Then you could also easily construct that callback yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants