workaround for vec2seq len issue

This commit is contained in:
Michael Sippel 2021-06-17 02:36:37 +02:00
parent 8e36e1c2fd
commit e7d1763369
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 12 additions and 6 deletions

View file

@ -34,13 +34,18 @@ where T: Clone + Send + Sync + 'static
data: Vec<T>, data: Vec<T>,
port: InnerViewPort<RwLock<Vec<T>>> port: InnerViewPort<RwLock<Vec<T>>>
) -> Self { ) -> Self {
let data = Arc::new(RwLock::new(data)); let mut b = VecBuffer::new(port);
port.set_view(Some(data.clone())); for x in data.into_iter() {
VecBuffer { data, cast: port.get_broadcast() } b.push(x);
}
b
} }
pub fn new(port: InnerViewPort<RwLock<Vec<T>>>) -> Self { pub fn new(port: InnerViewPort<RwLock<Vec<T>>>) -> Self {
VecBuffer::with_data(Vec::new(), port) let data = Arc::new(RwLock::new(Vec::new()));
port.set_view(Some(data.clone()));
VecBuffer { data, cast: port.get_broadcast() }
} }
pub fn apply_diff(&mut self, diff: VecDiff<T>) { pub fn apply_diff(&mut self, diff: VecDiff<T>) {

View file

@ -43,13 +43,14 @@ where T: Clone + Send + Sync + 'static {
fn reset(&mut self, view: Option<Arc<RwLock<Vec<T>>>>) { fn reset(&mut self, view: Option<Arc<RwLock<Vec<T>>>>) {
let old_len = self.cur_len; let old_len = self.cur_len;
self.data = view; self.data = view;
self.cur_len = self.cur_len = 0;
/*
if let Some(data) = self.data.as_ref() { if let Some(data) = self.data.as_ref() {
data.read().unwrap().len() data.read().unwrap().len()
} else { } else {
0 0
}; };
*/
self.cast.notify_each(0 .. std::cmp::max(old_len, self.cur_len)); self.cast.notify_each(0 .. std::cmp::max(old_len, self.cur_len));
} }