Conversation
|
I will add tests later, after the general approach in this implementation is decided acceptable. |
a93ef9d to
e68b754
Compare
|
|
||
| if (sequence !== this._queue[0]) { | ||
| var idx = this._queue.indexOf(sequence); | ||
| if (idx > 0) { |
There was a problem hiding this comment.
idx will never be 0 as sequence !== this._queue[0]. The sequence in this._queue[0] is the one that is currently being executed, isn't it?
Or you mean to change it to idx >= 1?
There was a problem hiding this comment.
My bad, missed previous line.
Btw maybe use separate method for removing sequence from queue? Its seems current method executes next sequence, but im not sure.
There was a problem hiding this comment.
@maximelkin I don't call Protocol._dequeue(sequence) directly. It is called from handler of Sequence.emit('end') emited from Query.end() called in my Query.dequeue(). I wanted to use the native query ending mechanism, so the query will call its _callback (with nothing) after being cancelled.
But yes, if we think it would be better, we could short circuit the native query ending mechanism, and just remove the query from the queue without calling Query.end() and emitting Sequence.emit('end'). But then the query _callback would never be called. I'm not sure if it would be good or not.
| if (this._started) { | ||
| throw new Error('Query already started.'); | ||
| } | ||
| this.end(); |
There was a problem hiding this comment.
I'm not entirelry sure calling this.end() here won't mess something. I've tracked the code, it seems to behave as expected: it calls this._callback with no results, emits end which calls Protocol._dequeue(this). But I'm not sure I covered all cases that may happen.
Resolves #2478