Closed pythoneer closed 4 years ago
I tried to make a PR but i failed in my first attempt to entangle the lifetimes with the mentioned "Initialization pattern". Its a little bit more involved than i though originally because the signer.with_signature
is also async and i don't really know how to pass that into the future without having a reference to self
. I think &self
on send is even a bigger problem because an immediate solution would be to move title
etc. right into Payload
– it think that's the way web-push is doing it. But i think the same also applies to web-push and fcm regarding &self
because .await
ing on &self
fields make it Pin
? idk.
Hey. I just saw this but already in bed. I'll check your code when I have my coffee tomorrow!
Hey @pythoneer please try the branch in that pull request. You can read the code how I just go with a blocking RwLock
for now, so I don't need to await it and can move the request building outside of the sending future. Now whatever gets captured in the sending future has a static lifetime and can be used together with spawn.
I don't think that blocking the thread with the signer lock will cause any trouble, but also I'm not working in a company that needs to send millions of notifications every minute anymore, so I can't really test...
It should be fine though, please give it a try.
(btw. the coffee is exceptionally good this morning)
(btw. the coffee is exceptionally good this morning)
Good coffee, happy life! :coffee:
Thanks @pimeys looks like it is working. Have tried it also on an actual device. I expect the same thing to be the case on fcm (maybe also web-push), should i open a separate issue? I am just not there in the process of porting these too, currently to say for sure.
It should be quite easy to fix them too. Why these problems happened originally is just me not being able to remember people might want to spawn these futures, due to me just running a consumer and spawning kafka messages instead of push notifications.
I'll fix fcm/web-push today.
0.5.1 is out.
First of all nice work and thanks for the quick release of version 0.5!
I am currently porting an actix-web(v0.7) application that uses a2(v0.4) to the new versions with
std::futures
(async/await) "support". Currently i am having some lifetime issues but i am not really sure why. Maybe its just me not seeing the obvious but i have the feeling that some lifetimes changed significantly from 0.4 -> 0.5I have made some minimal examples.
old one (a2 0.4, futures 0.1, actix-web 0.7) this one compiles
Cargo.toml
main.rs
new one (a2 0.5, futures 0.3, actix-web 2.0-alpha) this one does not compile
Cargo.toml
main.rs
having this compile errors:
Unfortunately i am not very familiar with the new futures 0.3 or maybe missing something obvious here. But from what i understand is that in version 0.4 the public send function and e.g. the private build_request have a lifetime
'a
from thePayload<'a>
and thus to the&title
,&message
and&token
stored in thatPayload<'a>
that is NOT bound to the return valueFutureResponse
because it looks like you are copying the values before "moving" them into futures likeand thus "guarding"
FutureResponse
from being bound to e.g.payload.device_token
I think this is not the case in version 0.5 Because send is anotated with
async
the return typeResult<Response, Error>
is auto wrapped with (i think)impl Future<Output = Result<Response, Error>> + 'a
binding the future onto the lifetime of its input parameters that result in my compilation errors? Because the hole function is now aFuture
and the copyingis just to late because we are already inside the future before copying?
EDIT I think this is roughly what happened
EDIT2 This is explicitly mentioned in the RFC 2394. My
lib_fn_new_same_lifetime
is mentioned as "Initialization pattern"