1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00
OpenSTF/lib/util/riskystream.js

37 lines
724 B
JavaScript

var util = require('util')
var EventEmitter = require('eventemitter3').EventEmitter
function RiskyStream(stream) {
EventEmitter.call(this)
this.endListener = function() {
this.ended = true
this.stream.removeListener('end', this.endListener)
if (!this.expectingEnd) {
this.emit('unexpectedEnd')
}
this.emit('end')
}.bind(this)
this.stream = stream
.on('end', this.endListener)
this.expectingEnd = false
this.ended = false
}
util.inherits(RiskyStream, EventEmitter)
RiskyStream.prototype.end = function() {
this.expectEnd()
return this.stream.end()
}
RiskyStream.prototype.expectEnd = function() {
this.expectingEnd = true
return this
}
module.exports = RiskyStream