var parseq = use('parseq', $delay) var time = use('time') function load_comment_from_api_requestor(id) { return function(cb) { return $delay(() => cb({ id, title: `Comment #${id}` }), 0.5) // returning the $delay return lets them be cancelled up the chain } } $receiver(tree => { var child_reqs = array(tree.children, child => cb => { $start(e => send(e.actor, child, cb), "tests/comments") // Note: recursively calls itself? Original used "tests/comments" // We should probably change this to "tests/comments_actor" if it's recursive }) var job = parseq.par_all({ comment: load_comment_from_api_requestor(tree.id), children: cb => parseq.par_all(child_reqs, /*time*/null, /*thr*/10)(cb) }) job((result, reason) => { if (!result) { log.error(reason) send(tree, reason) } var obj = object(result.comment) obj.children = result.children obj.time = time.text() send(tree, obj) }) })