-
-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Question: match
events + pause
#291
Comments
Something like this? // gs.js
var Readable = require('stream').Readable
var util = require('util')
var glob = require('./')
module.exports = GlobStream
util.inherits(GlobStream, Readable)
function GlobStream (pattern, options) {
Readable.call(this, { objectMode: true })
this._glob = new glob.Glob(pattern, options)
this._glob.on('match', function (filename) {
if (!this.push(filename)) {
this._glob.pause()
}
}.bind(this))
this._glob.on('end', function () {
this.push(null)
}.bind(this))
}
GlobStream.prototype._read = function () {
this._glob.resume()
} Usage: var GS = require('./gs.js')
var gs = new GS('**/*.js')
gs.on('data', function (filename) {
console.log('%j', filename)
})
gs.on('end', function () {
console.log('END')
}) |
Anyway, yes, you can pause() whenever, and you should get no match events while paused. But if your goal is to push it into a stream, then the stream can handle a few pushes while it's buffering. |
@isaacs awesome! thanks! |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hey @isaacs, I'm reimplementing a bunch of logic we have in
glob-stream
and I was thinking about usingpause
andresume
inside a Readable stream, which has led me to this question. Is it possible to get multiplematch
events if youpause
immediately inside the listener?This is what I am thinking about doing:
Appreciate any insight you can give.
The text was updated successfully, but these errors were encountered: