Preventing callbacks from accidentally being called twice

This commit is contained in:
Daniel García Aubert 2018-06-13 18:26:58 +02:00
parent 270daae579
commit 7d1a0abadd

View File

@ -15,12 +15,12 @@ module.exports = class StreamCopy extends EventEmitter {
to(cb) {
this.pg.connect((err, client, done) => {
if (err) {
cb(err);
return cb(err);
}
const copyToStream = copyTo(this.sql);
const pgstream = client.query(copyToStream);
pgstream
.on('error', err => {
if (!this.connectionClosedByClient) {
@ -40,7 +40,7 @@ module.exports = class StreamCopy extends EventEmitter {
from(cb) {
this.pg.connect((err, client, done) => {
if (err) {
cb(err);
return cb(err);
}
const copyFromStream = copyFrom(this.sql);
@ -50,7 +50,7 @@ module.exports = class StreamCopy extends EventEmitter {
.on('error', err => {
done();
cb(err, pgstream);
})
.on('end', () => {
done();