Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 21x 21x 21x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 21x 21x 21x 21x 21x 21x 4x 4x 4x 4x 4x 4x 4x 3x 3x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 3x 3x 3x 3x 4x 4x 4x 21x 21x 21x | const Readable = require('stream').Readable; const util = require('util'); function Scroll(client,query,options) { if (!(this instanceof Scroll)) return new Scroll(client,query,options); options = options || {}; options.objectMode = true; Readable.call(this,options); query.scroll = query.scroll || '10s'; this.client = client; this.query = query; this.options = options; } Scroll.prototype.buffer = []; util.inherits(Scroll,Readable); Scroll.prototype._read = function() { let paused; if (this.search) return; if (!this.scroll_id) this.search = this.client.search(this.query); else this.search = this.client.scroll({scroll_id: this.scroll_id, scroll: this.query.scroll}); return this.search .then(d => { if (d.body) d = d.body; this.search = undefined; this.scroll_id = this.scroll_id || d._scroll_id; if (!d.hits.hits.length) { this.scroll_id = undefined; return this.push(null); } d.hits.hits.forEach(d => paused = !this.push(d)); if (!paused) return this._read(); }) .catch(e => this.emit('error',e)); }; module.exports = Scroll; |