Add ended logic
This commit is contained in:
parent
acff0c0413
commit
8c35f8912c
@ -325,6 +325,7 @@ function ExportRequest (ostream, callback, beforeSink) {
|
|||||||
this.ostream = ostream;
|
this.ostream = ostream;
|
||||||
this.istream = null;
|
this.istream = null;
|
||||||
this.canceled = false;
|
this.canceled = false;
|
||||||
|
this.ended = false;
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
logger.info({ custom: true }, 'New export request');
|
logger.info({ custom: true }, 'New export request');
|
||||||
@ -373,17 +374,22 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
|
|||||||
.on('error', function (e) {
|
.on('error', function (e) {
|
||||||
logger.info({ custom: true }, 'Sending file: on error');
|
logger.info({ custom: true }, 'Sending file: on error');
|
||||||
console.log("Can't send response: " + e);
|
console.log("Can't send response: " + e);
|
||||||
|
that.ended = true;
|
||||||
that.ostream.end();
|
that.ostream.end();
|
||||||
that.cb(e);
|
that.cb(e);
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
logger.info({ custom: true }, 'Sending file: on end');
|
logger.info({ custom: true }, 'Sending file: on end');
|
||||||
|
that.ended = true;
|
||||||
that.cb();
|
that.cb();
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.on('close', function() {
|
.on('close', function() {
|
||||||
logger.info({ custom: true }, 'Sending file: testing on close event');
|
logger.info({ custom: true }, 'Sending file: testing on close event');
|
||||||
|
if (!that.ended) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logger.info({ custom: true }, 'It was cancelled (sending file)');
|
logger.info({ custom: true }, 'It was cancelled (sending file)');
|
||||||
|
Loading…
Reference in New Issue
Block a user