-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
combine on synchronous sources from array #414
Comments
I think this is a side-effect of how most stream libraries do subscribe to each stream in its given order. Most.js delays emissions until I'm not sure it's totally worth fixing IMO, as I don't actually see sources like Thanks for the issue. I'm sure it will lead to an interesting discussion. |
Here's a quick copy/paste of the OPs example in an esnextbin for those interested. https://esnextb.in/?gist=4a35680f3005d6267c37ad40a000b805 |
Yeah, I also see heavy use of multiple synchronous streams as pushing the limits of the paradigm too much. It becomes the wrong tool for the job (where e.g. arrays could do better). That said, I'm mostly worried if this issue expresses itself in a more subtle use case, because of course the example given above is the contrived and small. |
I think there are basically 4 options for these issues (across each library) after some discussion with @briancavalier.
|
Regarding number 3... it could be something like this import { Stream } from 'most';
export function mapArray(array, stream) {
return new Stream(new MapArray(array, stream.source))
}
class MapArray {
constructor(array, source) {
this.array = array;
this.source = source;
}
run (sink, scheduler) {
return this.source.run(new MapArraySink(this.array, sink), scheduler);
}
}
class MapArraySink {
constructor(array, sink) {
this.array = array;
this.length = array.length;
this.index = 0;
this.sink = sink;
}
event(time) {
const value = this.array[this.index];
this.sink.event(time, value);
if (++this.index > this.length)
this.sink.end(time, value);
}
error (time, err) { this.sink.error(time, err); }
end (time, value) { this.sink.end(time, value) }
}
// possible usage
const stream = mapArray([1, 2, 3], periodic(100));
observe(console.log, stream) This would give the behavior of an array of values a consistent and expected time component. |
While zip is generally applicable to lists, combineLatest is undefined without the time dimension. The current behavior is fine, because the solution is to introduce your own notion of time. Rx generally shies away from defining one for you. |
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. |
@staltz @TylorS @trxcllnt @briancavalier Sorry for poking you all with that in this already closed issue from 5 years ago, but I have no idea where to raise such a question, please let me know if you are aware of a better platform for that. I am pretty late in the game and trying to catch up what has happened and what is happening now in the reactive/js world. As I understand libraries trying to establish a "reactive" toolset quite "doubled down" on only using Related to this issue and maybe some similar problems with arrays in streams as well, I am wondering about a 4th somewhat meta-type like That way the meaning of these below would be less ambiguous I think:
I assume many other array related problems could be solved easier - and I just don't see the real drawback here, at least for such attempts. Was there such an attempt to build something on top of that? (Even if Sorry for being long and maybe using a bad platform, please let me know how/where you think to study these deeper. |
@PEZO19 The Observer defines |
Given this code
The log shows
While most people would expect it to display
By the way, I'm raising these issues also for xstream staltz/xstream#173 and RxJS ReactiveX/rxjs#2414. Is this is a bug or a feature? I'm not sure. What are people's ideas and opinions on this case?
The text was updated successfully, but these errors were encountered: