crypto-js: wait for device updates in getUserDevices (#1790)

Wait for up to a second for any in-flight device list updates to complete.
This commit is contained in:
Richard van der Hoff
2023-04-20 08:58:26 +01:00
committed by GitHub
parent a88f53ee85
commit 0da8e56a68
2 changed files with 10 additions and 2 deletions

View File

@@ -1,3 +1,8 @@
# v0.1.0-alpha.7
- In `OlmMachine.getUserDevices`, wait a limited time for any in-flight
device-list updates to complete.
# v0.1.0-alpha.6
- Add new accessor `InboundGroupSession.senderKey`.

View File

@@ -1,6 +1,6 @@
//! The crypto specific Olm objects.
use std::{collections::BTreeMap, ops::Deref};
use std::{collections::BTreeMap, ops::Deref, time::Duration};
use futures_util::StreamExt;
use js_sys::{Array, Function, Map, Promise, Set};
@@ -582,7 +582,10 @@ impl OlmMachine {
let me = self.inner.clone();
future_to_promise::<_, device::UserDevices>(async move {
Ok(me.get_user_devices(&user_id, None).await.map(Into::into)?)
// wait for up to a second for any in-flight device list requests to complete.
// The reason for this isn't so much to avoid races (some level of raciness is
// inevitable for this method) but to make testing easier.
Ok(me.get_user_devices(&user_id, Some(Duration::from_secs(1))).await.map(Into::into)?)
})
}