Skip to content
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

fix(ffi): don't panic when joining after having cancelled a media upload #4141

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{collections::HashMap, fmt::Write as _, fs, sync::Arc};
use std::{collections::HashMap, fmt::Write as _, fs, panic, sync::Arc};

use anyhow::{Context, Result};
use as_variant::as_variant;
Expand Down Expand Up @@ -1186,11 +1186,28 @@ impl SendAttachmentJoinHandle {

#[matrix_sdk_ffi_macros::export]
impl SendAttachmentJoinHandle {
/// Wait until the attachment has been sent.
///
/// If the sending had been cancelled, will return immediately.
pub async fn join(&self) -> Result<(), RoomError> {
let join_hdl = self.join_hdl.clone();
RUNTIME.spawn(async move { (&mut *join_hdl.lock().await).await.unwrap() }).await.unwrap()
let handle = self.join_hdl.clone();
let mut locked_handle = handle.lock().await;
let join_result = (&mut *locked_handle).await;
match join_result {
Ok(res) => res,
Err(err) => {
if err.is_cancelled() {
return Ok(());
}
error!("task panicked! resuming panic from here.");
panic::resume_unwind(err.into_panic());
}
}
}

/// Cancel the current sending task.
///
/// A subsequent call to [`Self::join`] will return immediately.
pub fn cancel(&self) {
self.abort_hdl.abort();
}
Expand Down
Loading