question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-atomic update of dependent stream created within a dependent stream

See original GitHub issue

Hi @paldepind,

Let me begin by saying nice work. I’ve really enjoyed using flyd so far. Thank you for sharing it with us all.

I’ve come across an edge case that I’m hoping you can help with. I did my best to uncover the cause in the source but had limited success.

Basically, when a dependent stream is created within the body of another stream, and that stream is triggered, the dependent streams dependents are updated twice. I would expect it to be updated only once since the top level stream was only triggered once.

It’s hard to describe in words. Here is an example that will allow you to reproduce the unexpected behavior:

const f = require('flyd');

const input = f.stream(); input.mark = 'input';
const oninput = f.on(v => {
  const s = f.stream(v); s.mark = 's';
  const ds = f.combine(s => s(), [s]); ds.mark = 'ds';
  const dds = f.on(v => console.log('dds:', v), ds); dds.mark = 'dds';
}, input); oninput.mark = 'oninput';
input(0);

// Console output:
//
// dds: 0
// dds: 0

From the best I was able to discern, when the oninput body runs, the following streams are added to the global toUpdate object: s, ds (not dds).

Then each of those streams have their dependencies updated: s => updateDeps: ds, dds ds => updateDeps: dds

Which results in dds being updated twice.

Thoughts?

Thanks for your help!

Best regards, Alex

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
anodynoscommented, Dec 8, 2016

Hello @paldepind & @c-dante - any updates on this issue?


PS: I should have started by saying thank you for this great composable FRP lib, so here you go 😃 I am evaluating it for a new frontend project where Rx would be an overkill and I’m getting hooked to it. I really like the fact it plays well with Ramda and FP principles, fantasy land etc unlike most other established libs.

With all due respect, I just wanted to know if the project is still alive and maintainable, cause it seems that lately there are both trivial & serious issues like this one that are hanging around…

Kind Regards

1reaction
garkincommented, Oct 31, 2017

I think, i just fixed it. npm install https://github.com/garkin/flyd/releases/tag/v0.2.4-forked

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update Dependencies | Microsoft Learn
In this article. Updating Aggregate Cells. Updating the value of a cell results in the updating of other dependent properties, such as FORMATTED_VALUE....
Read more >
What's the difference between the atomic and nonatomic ...
nonatomic means multiple thread access the variable (dynamic type). nonatomic is thread-unsafe. nonatomic is NOT default behavior. We need to add the nonatomic...
Read more >
An Introduction to Atomic Variables in Java - Baeldung
Learn how to use atomic variables for solving concurrency issues.
Read more >
CUDA C++ Programming Guide - NVIDIA Documentation Center
Operations that require a dependency check include any other commands within the same stream as the launch being checked and any call to...
Read more >
std::memory_order - cppreference.com
Writes to data-dependent variables in other threads that release the same atomic variable are visible in the current thread.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found