Conversation
|
This doesn't work var s = _([1, 2, 3]);
_([s.fork(), s.fork()])
.parallel(2)
.toArray(_.log);
// => prints nothing. |
|
I see. However, I don't quite understand why it doesn't work. Does |
|
Actually, I seem to have the same problem with |
|
It doesn't work with In contrast, if you run |
|
Ok. I've fixed that test case. Not sure if it is lazy enough right now. How would you want it to work? Should on start buffering item right away or after the first request? |
|
It should start buffering after the first request, since that's the current behavior of A few other things:
I have a working version of Though since |
|
Oh, and also
|
|
I would like to continue with this when I have spare time. Please do post your version. Even if we don't allow extra params with parallel it would be possible to achieve the same thing relatively simply using buffer. Do you think it would be a good idea to simplify the parallel implementation this way or would you rather leave that part as is? |
|
Let's leave function buffer(n, startImmediately) {
return function (s) {
var buffer = [];
var yieldRead = null;
var yieldWrite = null;
var handle = null;
s = s.consume(function (err, x, push, next) {
buffer.push([err, x]);
if (x !== _.nil) {
if (buffer.length < n) {
next();
}
else {
yieldRead = next;
}
}
if (yieldWrite) {
var yield = yieldWrite;
yieldWrite = null;
yield();
}
});
if (startImmediately) {
s.resume();
}
else {
yieldRead = s.resume.bind(s);
}
var ss = _(function (push, next) {
if (buffer.length > 0) {
var elem = buffer.shift();
push.apply(null, elem);
if (elem[1] !== _.nil) {
next();
}
} else {
yieldWrite = next;
}
if (yieldRead) {
var yield = yieldRead;
yieldRead = null;
yield();
}
});
return ss;
};
}One thing about the I think we'll be better off just dropping the parameter completely and always start immediately. There's a case to be made for being as lazy as possible, but since one of the main uses of Do you have a use-case for setting |
|
Hmm... |
Sounds reasonable. Only comment I have is that
Not really. As you write it doesn't make much sense. The reason I added it is due to the general practice of everything being lazy. |
|
Yeah, we try to keep everything as lazy as possible, but there are exceptions where it makes sense. For example, |
|
I'd actually have voted for This confused me a bit when data from stream2 got processed before stream1 was done, so that's just my 0.02$ for consideration. |
Adds
bufferoperator and implementsparallelin terms ofbufferwhich gives a simpler and more powerful solution.Needs test and review.