Skip to content

Instantly share code, notes, and snippets.

@soomtong
Created July 10, 2013 05:49
Show Gist options
  • Save soomtong/5963755 to your computer and use it in GitHub Desktop.
Save soomtong/5963755 to your computer and use it in GitHub Desktop.
패러랠 패턴
// async 모듈 사용시 형태
exports.getList = function (req, res) {
async.parallel([
// 메소드 1
// 메소드 2
// 메소드 3
], function (args) { // 반드시 필요한 콜백
//bind view page
res.render();
});
}
@outsideris
Copy link

순차적으로 실행하지 않아도 된다면 콜백내에서 콜백실행 갯수를 확인해서 할 수도 있고
아래처럼 재귀로 돌리면서 해도 됩니다.

exports.getList = function (req, res) {

  var length = 3;

  function repeater(index) {
    if (index < length) {
      // 메서드 1 or , 2 or 3
      repeater(index + 1);
    } else {
        //bind view page
        res.render();
    }
  }

  repeater(0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment