medea icon indicating copy to clipboard operation
medea copied to clipboard

ObservableField::when condition check before Future poll in 'medea-reactive' crate

Open evdokimovs opened this issue 3 years ago • 0 comments

Revealed from #159

Caused by #81

Summary

ObservableField::when and ObservableFild::when_eq instantly returns future::ok if provided condition already matches current value. But user expects that this computation will be performed on Future poll. This can cause bugs if someone will decide to poll received Future later.

Steps to reproduce

let mut val = Observable::new(0);
let when_fut = val.when(|i| i == 0);
*val.borrow_mut() = 1;

when_fut.await;

What is the current bug behavior?

when_fut Future will be resolved.

What is the expected correct behavior?

when_fut Future shouldn't be resolved because val's current value is no longer 0 when when_fut Future polled.

Possible fixes

Use Rc<RefCell<T>> as value storage in ObservableField, move cloned Rc to the returned Future and do this check in this Future.

evdokimovs avatar Dec 08 '20 11:12 evdokimovs