code: function readDependentJointsThatAreReady(unit, handleDependentJoint){
  	//console.log("readDependentJointsThatAreReady "+unit);
  	var t=Date.now();
  	var from = unit ? "FROM dependencies AS src_deps JOIN dependencies USING(unit)" : "FROM dependencies";
  	var where = unit ? "WHERE src_deps.depends_on_unit="+db.escape(unit) : "";
  	var lock = unit ? mutex.lock : mutex.lockOrSkip;
  	lock(["dependencies"], function(unlock){
  		db.query(
  			"SELECT dependencies.unit, unhandled_joints.unit AS unit_for_json, \n\
  				SUM(CASE WHEN units.unit IS NULL THEN 1 ELSE 0 END) AS count_missing_parents \n\
  			"+from+" \n\
  			JOIN unhandled_joints ON dependencies.unit=unhandled_joints.unit \n\
  			LEFT JOIN units ON dependencies.depends_on_unit=units.unit \n\
  			"+where+" \n\
  			GROUP BY dependencies.unit \n\
  			HAVING count_missing_parents=0 \n\
  			ORDER BY NULL", 
  			function(rows){
  				//console.log(rows.length+" joints are ready");
  				//console.log("deps: "+(Date.now()-t));
  				rows.forEach(function(row) {
  					db.query("SELECT json, peer, "+db.getUnixTimestamp("creation_date")+" AS creation_ts FROM unhandled_joints WHERE unit=?", [row.unit_for_json], function(internal_rows){
  						internal_rows.forEach(function(internal_row) {
  							handleDependentJoint(JSON.parse(internal_row.json), parseInt(internal_row.creation_ts), internal_row.peer);
  						});
  					});
  				});
  				unlock();
  			}
  		);
  	});
  }
docs: handleDependentJoint called for each dependent unit