mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
Move some screen utilities to the global util directory so that they can be used for other things too.
This commit is contained in:
parent
ae9f2b5ab0
commit
5bb05f52f6
4 changed files with 3 additions and 3 deletions
35
lib/util/riskystream.js
Normal file
35
lib/util/riskystream.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
var util = require('util')
|
||||
|
||||
var EventEmitter = require('eventemitter3').EventEmitter
|
||||
|
||||
function RiskyStream(stream) {
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue