Skip to content

Multiple fields in AppState, how to share multiple state between routes? #1758

Discussion options

You must be logged in to vote

Thank you for your haste.

I was able to reproduce my issue by making the kv store example resemble mine.

The only change is in the kv_set function, where I add an await for tokio::sleep in between aquiring a write lock and then using the db.

This code below does not compile due to this locking issue. The data structure I'm using is not Send, so it can't be safely sent across threads. However, theres an 'await' between where the lock is acquired and where db is accesed. So for that thread to be put into the tokio runtime, it needs to do exactly that which it can't therefore the issue.

Is that a fair interpretation of the situation?

How do I get around this? Is there a better way to go abou…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@davidpdrsn
Comment options

Answer selected by matthiasdebernardini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants