I'm trying to port my toy program from mioco to tokio/futures but I have problems with the lifetime of references.
The main problem seems to be that threads/coroutines play nicely with lifetime because they have an implicit state on the stack.
The explicit state of futures seems to be much less flexible with regards to references. Especially tokio_core::reactor::Handle::spawn
, which requires 'static
bounds on the future.
With coroutines/threads, I can always use an Arc
to get a "global" object into the closure and then borrow it for the entire lifetime of the closure, even through context switches.
With futures, I can also use an Arc
, but I can only borrow it during a single poll
.
I there a way to create keep an Arc
/Rc
an a reference in a struct, where both refer to the same object?
Like:
struct A<'a> {
barc: Arc<B>,
bref: &'a B,
}
It doesn't have to be an Arc
, just something to tie the lifetime of the B
object to the lifetime of A
.
Is something like this even possible?