The idea is that I need to run multiple operations against the database, but only if I need to. For instance if there are no items to insert, then there is no insert call.
function dbOperations(params){ functionInsert(params) .then(functionUpdate(params)) .then(functionDelete(params)) ... } then I have
function functionInsert(params){ if (params){ //DO a call against DB which returns a promise return knex.insert().transacting(trx); }else{ //if no params, no need to do anything, just let the next .then() fire next function return Promise.resolve() } } By having it like that, the code runs fine but when there are no params then I see this warning Warning: .then() only accepts functions but was passed: [object Object] so it's obvious I am doing something wrong.
How should this scenario be handled, when there are no params?
LE: for db access I am using knex. I've edited the functionInsert above.
theninto some closure to make them execute only whenthenis called (as opposed to calling it immediately and passing the result tothen)? something like.then( function(){ functionUpdate(params)})functionUpdateand/orfunctionDeleteare returning object instead of function when there are no params.paramsare present is thatfunctionInsertdoes then not return a Promise, but a function that returns a Promise.promiseFromORMvspromiseFromORM(). It probably works if you doPromise.resolveinstead ofPromise.resolve().then(function...generates blocking between operations. Maybe my functions are called in parallel and not one after the other? It is really important to have them run one after another do avoid deadlocks