• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by John Dev


28 Nov, 2024

Updated at 12 Dec, 2024

How do I poll a Stream behind a RwLock?

I have an axum server with a state struct. In it I want to use delay_map::HashMapDelay to keep a map of sessions that are removed after a timeout. Since the state is shared, the map is under a tokio::sync::RwLock.

But from what I understand, in order to actually remove the expired entries, I need to call next() since it's a Stream. So I'm trying to spawn a task that does that in a loop. However, since the map is behind a RwLock, I can't make that work, it gets stuck; I think it deadlocks since it needs to hold the lock while it waits in the next() call.

Any suggestions on how to make this work, or maybe a totally different approach to do the same thing?

1 post - 1 participant

Read full topic