Tuesday, 14 March 2017

Error : Callback was already called when using pg-promise with async series

I'm having trouble understanding the output printed why executing this code :

1 2 Unhandled rejection Error: Callback was already called.

It seems like both then and catch are executed when the query is successful.

Any idea ?

Cheers

async.series([
        function(callback) {
            db.none(query)
                .then(function () {
                    return callback(null, true);
                })
                .catch(function (err) {
                    return callback(err, null);
                });
        },
        function(callback) {
            db.any(query)
                .then(function (data) {
                    console.log('1')
                    return callback(null, data);
                })
                .catch(function (err) {
                    console.log('2')
                    return callback(err, null);
                });
        }
    ],
    function(err, results) {});



via antoinecsk

No comments:

Post a Comment