proposal-signals icon indicating copy to clipboard operation
proposal-signals copied to clipboard

Watchers have inconsistent state inside `watched` callback

Open prophile opened this issue 1 year ago • 1 comments

Consider the following code:

let watcher
const a = new Signal.State(0, {
  [Signal.subtle.watched]: () => {
    console.log(Signal.subtle.introspectSinks(a))
    console.log(Signal.subtle.introspectSources(watcher))
  },
})

watcher = new Signal.subtle.Watcher(() => {
  console.log("notified")
});
watcher.watch(a);

Inside the watched callback, a is reported as having no sinks, but watcher does have a as a source – a visibly inconsistent state.

prophile avatar Apr 29 '24 18:04 prophile

This could be solved either way, by updating both before the callback or both after. I have no opinion on the options.

littledan avatar May 28 '24 15:05 littledan