Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

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

Open
evdokimovs opened this issue Dec 8, 2020 · 0 comments
Labels
bug Something isn't working enhancement Improvement of existing features or bugfix k::api Related to API (application interface) k::refactor Refactoring, technical debt elimination and other improvements of existing code base

Comments

@evdokimovs
Copy link
Contributor

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 evdokimovs added bug Something isn't working enhancement Improvement of existing features or bugfix k::api Related to API (application interface) k::refactor Refactoring, technical debt elimination and other improvements of existing code base labels Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement Improvement of existing features or bugfix k::api Related to API (application interface) k::refactor Refactoring, technical debt elimination and other improvements of existing code base
Projects
None yet
Development

No branches or pull requests

2 participants