Pattern for calling async methods on members of the application object... ? #1866
Unanswered
andretietz
asked this question in
Q&A
Replies: 1 comment
-
For long-lived objects that need to be kept in the state but are used from async contexts use a smart pointer like std::sync::Arc. This way you can clone your Arc (knowing that it requires no (much) more memory than a normal pointer) and pass it by value to your async function without problem. If you need mutable access there are other options available too. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been hitting this problem and I wonder if this isn't a common problem already and might have a good pattern to solve...
I am comparable young to rust, so please forgive me if this is a straight forward question :/
Following code doesn't compile:
Here the error message:
Problem here is that the async part might be executed when
Self
is not alife anymore.Is there a common pattern that is used to do things like this?
What I do to work around this atm, is creating a function, that recreates the
database
everytime I need do something with it (no memberdatabase
in my Application object anymore), which seems odd...Beta Was this translation helpful? Give feedback.
All reactions