Thursday, 5 December 2019

Can Promises do this?

Hey,So I'd like to know if promises can solve this problem.I have an outer callback function and an inner callback function (for manipulating a database). This is what I want to do:-Run the first half of the outer callback function. -Run my inner callback function fully -Once the inner callback finishes, run the second half of the outer callback function.I tried this normally, but the outer callback runs fully before the inner callback function.Here's how it's structured:outFunc((err, rows) => { //Run outer code first half inFunc((err, rows)=> { //Run Inner code }); //Run outer code second half });I tried doing this normally but it doesn't work (race condition?)So I was wondering, can this be solved with Promises, or is there a better solution? Are there resources to guide me? (complete beginner).Thanks in advance!

Submitted December 05, 2019 at 11:09PM by indisapien

No comments:

Post a Comment