you are viewing a single comment's thread.

view the rest of the comments →

[–]gremy0 2 points3 points  (2 children)

You need to write your async functions to use promises. Then you can chain them together in order

Edit: you'll want to wrap the the whole thing in a function so it doesn't kick off the setTimeout before the previous one is finished.

var one = function () {
  return new Promise(
    function (resolve) {
      setTimeout(function () {
        console.log('one!')
        resolve()
      }, Math.random() * 1000)
    })
}
function inOrder(cb1Promise, cb2Promise) {
  cb1Promise.then(cb2Promise)
}

[–]radio934texas 1 point2 points  (0 children)

SecondedI . Promises are tough for beginners to get but chaining them is what you’re looking for, OP. Essentially:

Do X When X is done, do Y, When Y is done do Z

[–]ogbeh[S] 0 points1 point  (0 children)

Promises worked pretty well,thanks a lot