Posted to tcl by bairui at Mon Feb 15 00:05:08 GMT 2016view raw

  1. #! /usr/bin/env tclsh
  2.  
  3. package require Thread
  4. package require promise
  5.  
  6. # "works" in that it returns results,
  7. # but understandably synchronous.
  8.  
  9. set promises [lmap path $argv {promise::Promise new [promise::lambda {path prom} {
  10. set command "exec -ignorestderr du -sk"
  11. lappend command $path
  12. lappend command "2>/dev/null"
  13. try {
  14. set result [{*}$command]
  15. } on error {result opts} {
  16. # spurious, fragile and specific to du command on linux
  17. set result [concat {*}[lrange [split $result "\n"] end-1 end-1]]
  18. }
  19. puts $result
  20. return $result
  21. } $path]}]
  22.  
  23. set all_done [promise::all $promises]
  24.  
  25. $all_done then [promise::lambda {outputs} {
  26. foreach output $outputs {puts $output}
  27. }]
  28.  
  29. vwait forever
  30.