diff --git a/copy-both.js b/copy-both.js index 7f3bd0f..fdd459b 100644 --- a/copy-both.js +++ b/copy-both.js @@ -218,12 +218,10 @@ class CopyStreamQuery extends Duplex { if (callback) { if (ok) { callback() + } else if (this.chunks.length) { + this.connection.stream.once('drain', this.flush.bind(this, callback)) } else { - if (this.chunks.length) { - this.connection.stream.once('drain', this.flush.bind(this, callback)) - } else { - this.connection.stream.once('drain', callback) - } + this.connection.stream.once('drain', callback) } } } diff --git a/copy-from.js b/copy-from.js index 2e4c3be..d548d3f 100644 --- a/copy-from.js +++ b/copy-from.js @@ -103,12 +103,10 @@ class CopyStreamQuery extends Writable { if (callback) { if (ok) { callback() + } else if (this.chunks.length) { + this.connection.stream.once('drain', this.flush.bind(this, callback)) } else { - if (this.chunks.length) { - this.connection.stream.once('drain', this.flush.bind(this, callback)) - } else { - this.connection.stream.once('drain', callback) - } + this.connection.stream.once('drain', callback) } } }