Posted to tcl by apn at Thu Feb 10 05:35:40 GMT 2022view raw

  1. # Original code, simplified without zip and email
  2.  
  3. package require promise
  4. namespace path promise
  5. set urls [list http://www.example.com http://www.tcl-lang.org]
  6. proc print_done args {puts "All done!"}
  7. proc save_file args {}
  8. set promises [lmap url $urls {
  9. [pgeturl $url] then [lambda {dir url http_state} {
  10. save_file $dir $url [dict get $http_state body]
  11. } /tmp $url]
  12. }]
  13. set gate [all $promises]
  14. $gate done print_done
  15.  
  16.  
  17. # Above example with additional requirement to run du in parallel
  18. package require promise
  19. namespace path promise
  20. set urls [list http://www.example.com http://www.tcl-lang.org]
  21. proc print_done args {puts "All done!"}
  22. proc save_file args {}
  23. set promises [lmap url $urls {
  24. [pgeturl $url] then [lambda {dir url http_state} {
  25. save_file $dir $url [dict get $http_state body]
  26. } /tmp $url]
  27. }]
  28. lappend promises [pexec du -sk /tmp]; # Single line added
  29. set gate [all $promises]
  30. $gate done print_done
  31.