Friday 18 December 2015

How do I continue coding after promises?

Hello all,Here's a question I haven't been able to figure out.Currently, I'm working on some code that requires me to do a long running operation first.To ensure that it finishes, I make use of promises.longRunningOp(args) .then(nextOp) .then(nextOp) My question is ( and I believe this is poorly worded but) How does one switch from async to sync programming after a promise has executed?For example, what if I had a "main" function where I'm executing multiple functions.//Main var x = doSomething(y) ... ... //Want to do a long Op longOp(y) .then(functionx) .then(functiony) Instead of going into function x, and function y individually. Is there anyway to return how I was doing it in the "main" before the long running operation where all of the functions (provided that they're not long) would get executed in order?OR. Am I doing this all wrong and since node is inherently asynchronous, I should be doing everything in promises, if anything's going to use promises?(Further clarification: What I'm looking for is a way that i can doMainstuff LongRunningQuery .then( more main stuff here. ) )

Submitted December 18, 2015 at 05:43PM by TLI5

No comments:

Post a Comment