Основываясь на http://i.stack.imgur.com/9DDQP.png, вам нужна хорошая библиотека потоков, которая позволяет передавать по конвейеру синхронизированные и асинхронные вызовы в узле.
Одна из таких библиотек - https://github.com/isaacs/slide-flow-control (посмотрите там также slide preso ), а схема кода для того, что вам нужно сделать, приведена ниже.
Он самодокументирован и, как вы видите, он довольно лаконичен, чистых nodejs, uml, img и т. Д. Не требуется.
var chain = require("slide/chain")
, asyncMap = require("slide/async-map")
;
// start processing
main_loop(function() {
console.log("its done"); // when finished
});
function main_loop(cb) {
var res = [];
// each entry in chain below fires sequentially i.e. after
// the previous function completes
chain
( [ [start_update_q, "user-foo"]
, [get_followed_users, chain.last]
, [get_favorites, chain.last]
, [calc_new_q]
, [push_results, chain.last]
]
, res
, cb
)
}
function get_favorites(users, cb) {
function fn(user, cb_) {
get_one_users_favorites(user, cb_);
}
// this will run thru get_favorites in parallel
// and after all user favorites are gotten it will fire
// callback cb
asyncMap(users, fn, cb);
}
// code in the various functions in chain here,
// remember to either return the callback on completion.
// or pass it as an arg to the async call you make within the
// function as above i.e. asyncMap will fire cb on completion