-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send a multi device sent transcript content #38
Send a multi device sent transcript content #38
Conversation
f0c4ed1
to
9090248
Compare
This can probably go away when fixing multidevice transcripts, i.e. #38
…-transcript-content
…-transcript-content
…-transcript-content
26de436
to
1676d43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the reason you drop mut
is because create_encrypted_message
and partners are called concurrently (because you want to drive them with join_all
), and that would yield interleaved mutable borrows.
Some remarks:
- I am still in favour of keeping the most generic interface (which is with
mut
as restriction) - While concurrently sending the individual messages does make sense, I can imagine it doesn't provide much benefit in practice.
pub struct Foo;
impl Foo {
async fn fun(&mut self) -> Result<(), ()> {
Ok(())
}
async fn some_concurrent(&mut self) {
let multiple = (0..4).map(|_| self.fun());
let results = futures::future::join_all(multiple).await;
}
}
#[tokio::main]
async fn main() {
let results = Foo.some_concurrent().await;
}
... rightfully yields
error: captured variable cannot escape `FnMut` closure body
--> src/main.rs:9:39
|
9 | let multiple = (0..4).map(|_| self.fun());
| - ^^^^^^^^^^ returns a reference to a captured variable which escapes the closure body
| |
| inferred to be a `FnMut` closure
|
= note: `FnMut` closures only have access to their captured variables while they are executing...
= note: ...therefore, they cannot allow references to captured variables to escape
On the other hand, Rust by default assumes that the async fn fun
's Future needs to live for the lifetime of &mut self
, which is not necessarily true:
pub struct Foo;
impl Foo {
fn fun<'a>(&'a mut self) -> impl std::future::Future<Output=Result<(), ()>> + 'static {
async { Ok(()) }
}
async fn some_concurrent(&mut self) {
let multiple = (0..4).map(|_| self.fun());
let results = futures::future::join_all(multiple).await;
}
}
#[tokio::main]
async fn main() {
let results = Foo.some_concurrent().await;
}
I wonder whether it's possible to re-engineer the try_send_message
method to use a shared mutable reference. On the other hand, making a custom self parameter (like async fn try_send_message(self: RefCell<&mut Self>, ...
) doesn't necessarily make things better here, especially since that trickles down into implementors. Even worse would probably be to use a futures::lock::Mutex
for this. I wonder whether there's a (near-)free type to solve this kind of issue...
Yes, this is exactly the reason why I wanted to drop the mutable borrow. For now I'll drop it entirely and keep it as it is. (also: sending multiple requests at the same time actually got me rate limited a few times). |
@rubdos I think this is more or less in a OK state, I kind of lost track on the way and the change is rather big. I haven't been able to test group sending yet, and will do soon, but I think you can already give a look to the changes since your last review. |
…-transcript-content
556df3f
to
be34f4a
Compare
If it's tested (including group) I think this is good to go. |
whisperfish/libsignal-service-rs#38 Ending sessions is now handled in service too (related to aebruno#102)
Saved less code than I hoped. Meh :'-) |
What a great name... this is similar to what's in https://gitlab.com/rubdos/whisperfish/-/blob/master/src/worker/client.rs#L527 and https://github.com/signalapp/libsignal-service-java/blob/1a01c22636ad2c4e24e911ed7c4eb95f14cc58d6/java/src/main/java/org/whispersystems/signalservice/api/SignalServiceMessageSender.java#L615
EDIT by Ruben:
send_message
improved will also include itShould also address or give an answer to UnidentifiedAccess: method parameter vs MessageSender field #49reducing scope since we always send a sync a message without providing theUnidentifiedAccess
https://github.com/Michael-F-Bryan/libsignal-service-rs/pull/38/files#diff-9ae521e6fffe43a399d2d3007bbccc81a73e245f5aa5663b007af1fa97dbcc26R255