lib/database.js
function taskProcessor(params, isTX) {

            if (typeof params.cb !== 'function') {
                return $p.reject(new TypeError('Callback function is required.'));
            }

            if (params.options.reusable) {
                return config.$npm.task.callback(obj.ctx, obj, params.cb, config);
            }

            const taskCtx = ctx.clone(); // task context object;
            if (isTX) {
                taskCtx.txLevel = taskCtx.txLevel >= 0 ? (taskCtx.txLevel + 1) : 0;
            }
            taskCtx.inTransaction = taskCtx.txLevel >= 0;
            taskCtx.level = taskCtx.level >= 0 ? (taskCtx.level + 1) : 0;
            taskCtx.cb = params.cb; // callback function;
            taskCtx.mode = params.options.mode; // transaction mode;
            if (this !== obj) {
                taskCtx.context = this; // calling context object;
            }

            const tsk = new config.$npm.task.Task(taskCtx, params.options.tag, isTX, config);
            taskCtx.taskCtx = tsk.ctx;
            extend(taskCtx, tsk);

            if (taskCtx.db) {
                // reuse existing connection;
                npm.utils.addReadProp(tsk.ctx, 'useCount', taskCtx.db.useCount);
                return config.$npm.task.execute(taskCtx, tsk, isTX, config);
            }

            // connection required;
            return config.$npm.connect.pool(taskCtx, dbThis)
                .then(db => {
                    taskCtx.connect(db);
                    npm.utils.addReadProp(tsk.ctx, 'useCount', db.useCount);
                    return config.$npm.task.execute(taskCtx, tsk, isTX, config);
                })
                .then(data => {
                    taskCtx.disconnect();
                    return data;
                })
                .catch(error => {
                    taskCtx.disconnect();
                    return $p.reject(error);
                });
        }
function taskProcessor(params, isTX) {

            if (typeof params.cb !== 'function') {
                return $p.reject(new TypeError('Callback function is required.'));
            }

            if (params.options.reusable) {
                return config.$npm.task.callback(obj.ctx, obj, params.cb, config);
            }

            const taskCtx = ctx.clone(); // task context object;
            if (isTX) {
                taskCtx.txLevel = taskCtx.txLevel >= 0 ? (taskCtx.txLevel + 1) : 0;
            }
            taskCtx.inTransaction = taskCtx.txLevel >= 0;
            taskCtx.level = taskCtx.level >= 0 ? (taskCtx.level + 1) : 0;
            taskCtx.cb = params.cb; // callback function;
            taskCtx.mode = params.options.mode; // transaction mode;
            if (this !== obj) {
                taskCtx.context = this; // calling context object;
            }

            const tsk = new config.$npm.task.Task(taskCtx, params.options.tag, isTX, config);
            taskCtx.taskCtx = tsk.ctx;
            extend(taskCtx, tsk);

            if (taskCtx.db) {
                // reuse existing connection;
                npm.utils.addReadProp(tsk.ctx, 'useCount', taskCtx.db.useCount);
                return config.$npm.task.execute(taskCtx, tsk, isTX, config);
            }

            // connection required;
            return config.$npm.connect.pool(taskCtx, dbThis)
                .then(db => {
                    taskCtx.connect(db);
                    npm.utils.addReadProp(tsk.ctx, 'useCount', db.useCount);
                    return config.$npm.task.execute(taskCtx, tsk, isTX, config);
                })
                .then(data => {
                    taskCtx.disconnect();
                    return data;
                })
                .catch(error => {
                    taskCtx.disconnect();
                    return $p.reject(error);
                });
        }
function taskProcessor ( params , isTX ) { if ( typeof params . cb !== 'function' ) { return $p . reject ( new TypeError ( 'Callback function is required.' ) ) ; } if ( params . options . reusable ) { return config . $npm . task . callback ( obj . ctx , obj , params . cb , config ) ; } const taskCtx = ctx . clone ( ) ; // task context object; if ( isTX ) { taskCtx . txLevel = taskCtx . txLevel >= 0 ? ( taskCtx . txLevel + 1 ) : 0 ; } taskCtx . inTransaction = taskCtx . txLevel >= 0 ; taskCtx . level = taskCtx . level >= 0 ? ( taskCtx . level + 1 ) : 0 ; taskCtx . cb = params . cb ; // callback function; taskCtx . mode = params . options . mode ; // transaction mode; if ( this !== obj ) { taskCtx . context = this ; // calling context object; } const tsk = new config . $npm . task . Task ( taskCtx , params . options . tag , isTX , config ) ; taskCtx . taskCtx = tsk . ctx ; extend ( taskCtx , tsk ) ; if ( taskCtx . db ) { // reuse existing connection; npm . utils . addReadProp ( tsk . ctx , 'useCount' , taskCtx . db . useCount ) ; return config . $npm . task . execute ( taskCtx , tsk , isTX , config ) ; } // connection required; return config . $npm . connect . pool ( taskCtx , dbThis ) . then ( db => { taskCtx . connect ( db ) ; npm . utils . addReadProp ( tsk . ctx , 'useCount' , db . useCount ) ; return config . $npm . task . execute ( taskCtx , tsk , isTX , config ) ; } ) . then ( data => { taskCtx . disconnect ( ) ; return data ; } ) . catch ( error => { taskCtx . disconnect ( ) ; return $p . reject ( error ) ; } ) ; }
Task method; Resolves with result from the callback function;
Task method ; Resolves with result from the callback function ;