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

#! /usr/bin/env tclsh

package require Thread
package require promise

# "works" in that it returns results,
# but understandably synchronous.

set promises [lmap path $argv {promise::Promise new [promise::lambda {path prom} {
    set     command "exec -ignorestderr du -sk"
    lappend command $path
    lappend command "2>/dev/null"
    try {
      set result [{*}$command]
    } on error {result opts} {
      # spurious, fragile and specific to du command on linux
      set result [concat {*}[lrange [split $result "\n"] end-1 end-1]]
    puts $result
    return $result
  } $path]}]

set all_done [promise::all $promises]

$all_done then [promise::lambda {outputs} {
    foreach output $outputs {puts $output}

vwait forever