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.

combine on synchronous sources from array

See original GitHub issue

Given this code

const a$ = most.from([1,2])
const b$ = most.from([10]);

const c$ = most.combine((a,b)=>a+b, a$, b$);

c$.subscribe({next: c => console.log(c)});

The log shows

12

While most people would expect it to display

11
12

By the way, I’m raising these issues also for xstream https://github.com/staltz/xstream/issues/173 and RxJS https://github.com/ReactiveX/rxjs/issues/2414. Is this is a bug or a feature? I’m not sure. What are people’s ideas and opinions on this case?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
briancavaliercommented, Mar 6, 2017

I’m ok with saying that the current behavior is correct for 1.x. Like both @trxcllnt and @TylorS have pointed out, values from an array (or other synchronously available data structure) are not really events, they’re simply data, and as such they have no time dimension. There is an implicit time imposed on them based on the instant of observation, but it’s artificial. They’re simultaneous, but indexed.

For now, I think we can say that when given a bunch of simultaneous indexed values, combine() observes the last (“last” as in index order) one.

What I don’t like is that the API allows a user to do get into this situation in the first place. The only way to prevent it currently is to tell users not to do it. Let’s think about ways we can prevent it in the future. The best solution may turn out to be @TylorS’s option 3.

2reactions
TylorScommented, Feb 24, 2017

I think there are basically 4 options for these issues (across each library) after some discussion with @briancavalier.

  1. “Solve” the confusion via documentation. Ensure it is clearly marked that synchronously emitting “events” are not just synchronous but simultaneous, and that combine always observes the last (as in order not time) simultaneous event.
  2. Do lots of buffering (large performance impact)
  3. Remove these APIs that don’t produce “true” events. Instead provide a kind of overlay for arrays of values that operate on top of streams that do produce predictable and sane timing behaviors.
  4. Asynchronously emit each value one after another, which also feels very unexpected just like the current behavior.
Read more comments on GitHub >

github_iconTop Results From Across the Web

combineLatest on synchronous sources · Issue #2414 - GitHub
Forcing queue scheduling on an operator in JavaScript is like trying to force the library to mimic some sort of gated/threaded model, which...
Read more >
Combine framework: how to process each element of array ...
Combine framework: how to process each element of array asynchronously before proceeding ; Fetch info from online database, it's an array · For ......
Read more >
Different Methods for Combining Arrays - YouTube
Arrays are an important data structure to learn. In this tutorial we will look at different methods for combining arrays.
Read more >
Connecting and merging Combine publishers in Swift
In Combine, the map operator lets us synchronously transform an output value into a new type of value, while the flatMap operator lets...
Read more >
Learn to combine RxJs sequences with super intuitive ...
The first operator we'll review is combineLatest . It allows you to take the most recent value from input sequences and transform those...
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