ObservableField::when condition check before Future poll in 'medea-reactive' crate
Opened this issue · 0 comments
evdokimovs commented
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
.