Writing in coffeescript but the principle is the same, I'm calling ps.list and ps.read (from the pslook module in the npm registry). These functions don't return results but call the callback passed to them. The setTimeout is not what I want to do, but am having trouble thinking of a way around this.. any ideas? Not sure if IcedCoffeeScript can help here in any way?
ps = require 'pslook'
instances = []
ps.list (err, results) ->
if err then throw err
results.forEach (result) ->
ps.read result.pid, (err, process) ->
if err then throw err
instances.push process.cmdline
, 'fields': ps.ALL
, 'search': /^ssh/
setTimeout ->
console.dir instances
### Do lots more stuff here with the list of instances that I don't want to be nested within calls to ps.list / ps.read
, 500