Tokio select with look-ahead

⚓ Rust    📅 2025-09-28    👤 surdeus    👁️ 12      

surdeus

Warning

This post was published 113 days ago. The information described in this article may have changed.

I have a tokio task that listens to two channels channel A and channel B. Both channels carry the same type of objects. These objects contain a timestamp. I would like to have my task listen to both channels and if one of them has an object, then it should take it and process it. If both of them have an object I want to take the one with the smallest timestamp and if the timestamps are the same, I want to take the object of channel A.

How can I do that in a non-messy way? I started writing it but it became an unreadable mess and I bet there is a clean native way to do that.

1 post - 1 participant

Read full topic

🏷️ Rust_feed