coffeescript - javascript synchronous call -
this question has answer here:
writing in coffeescript principle same, i'm calling ps.list , ps.read (from pslook module in npm registry). these functions don't return results call callback passed them. settimeout not want do, having trouble thinking of way around this.. ideas? not sure if icedcoffeescript can here in way?
ps = require 'pslook' instances = [] ps.list (err, results) -> if err throw err results.foreach (result) -> ps.read result.pid, (err, process) -> if err throw err instances.push process.cmdline , 'fields': ps.all , 'search': /^ssh/ settimeout -> console.dir instances ### lots more stuff here list of instances don't want nested within calls ps.list / ps.read , 500
what simple counter waits callbacks called?
untested example:
ps.list (err, results) -> if err throw err waitingfor = results.length results.foreach (result) -> ps.read result.pid, (err, process) -> if err throw err instances.push process.cmdline waitingfor -= 1 goon(instances) if waitingfor == 0 , 'fields': ps.all , 'search': /^ssh/ goon (instances) -> console.dir instances
Comments
Post a Comment