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

Added remove_if to priority channel #3523

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Gibbz
Copy link
Contributor

@Gibbz Gibbz commented Nov 11, 2024

Added remove_if to priority channel. This allows removing items from the queue if there is a match in the predicate.
You can also do this on a sender, receiver and the channel directly itself.

In my sample code I use the following:

let send_ble_queue = QUEUE_CHANNEL.sender();
send_ble_queue.remove_if(|i| { i.handle == handle && i.is_single_instance() });

This is for my issue here: #3431

@Dirbaio
Copy link
Member

Dirbaio commented Dec 2, 2024

  • It feels wrong that the sender can remove items from the channel. Ideally the sender should only be able to add, the receiver should only be able to remove.
  • I'm not sure about the feature, it feels a bit ad-hoc to your particular use case. If you need to dedup maybe you want global bools or signals denoting "does X need to be done?" instead of a queue, that will dedup "for free"

@Gibbz
Copy link
Contributor Author

Gibbz commented Dec 3, 2024

Can you give me a bit more information on how you would implement your second point?

I'm using the que as some items need to sent in order, such as multiple log events.

Most everything else simply needs priority. And these items really only need to send the latest information, so the older information can be dropped off it had not been sent yet.

Is this something you want to merge, or should I just implement it specifically for my project?

@lulf
Copy link
Member

lulf commented Dec 3, 2024

Filtering/selectors are not unusual when using queues, but I think this should only be on the receiver end. One alternative is to use one queue per case you wish to filter on. On the sender side you can anyway filter before you push so there's not really a need for additional APIs there.

@lulf
Copy link
Member

lulf commented Dec 3, 2024

To be clear, what I think would make sense is:

let item = receiver.receive_with_filter(|i| i.priority == 0).await;

@Gibbz
Copy link
Contributor Author

Gibbz commented Dec 3, 2024

Okay thanks. I'll update the pr soon 👍

@Gibbz
Copy link
Contributor Author

Gibbz commented Dec 14, 2024

I've updated this removing the sender from using the function. It doesn't seem to be building for some reason. Any idea why this is getting stuck?

@Dirbaio

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.

3 participants