1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-03 17:59:28 +02:00

Hopefully get rid of FrameProducer._stop() timeouts. Doesn't reproduce locally.

This commit is contained in:
Simo Kinnunen 2015-07-15 14:13:31 +09:00
parent cfc84a0e42
commit dc07777829
3 changed files with 52 additions and 42 deletions

View file

@ -1,5 +1,6 @@
var util = require('util')
var Promise = require('bluebird')
var EventEmitter = require('eventemitter3').EventEmitter
function RiskyStream(stream) {
@ -34,4 +35,27 @@ RiskyStream.prototype.expectEnd = function() {
return this
}
RiskyStream.prototype.waitForEnd = function() {
var stream = this.stream
, endListener
this.expectEnd()
return new Promise(function(resolve/*, reject*/) {
if (stream.ended) {
return resolve(true)
}
stream.on('end', endListener = function() {
resolve(true)
})
// Make sure we actually have a chance to get the 'end' event.
stream.resume()
})
.finally(function() {
stream.removeListener('end', endListener)
})
}
module.exports = RiskyStream