Posted to tcl by apn at Thu Feb 10 05:35:40 GMT 2022view raw
- # Original code, simplified without zip and email
- package require promise
- namespace path promise
- set urls [list http://www.example.com http://www.tcl-lang.org]
- proc print_done args {puts "All done!"}
- proc save_file args {}
- set promises [lmap url $urls {
- [pgeturl $url] then [lambda {dir url http_state} {
- save_file $dir $url [dict get $http_state body]
- } /tmp $url]
- }]
- set gate [all $promises]
- $gate done print_done
- # Above example with additional requirement to run du in parallel
- package require promise
- namespace path promise
- set urls [list http://www.example.com http://www.tcl-lang.org]
- proc print_done args {puts "All done!"}
- proc save_file args {}
- set promises [lmap url $urls {
- [pgeturl $url] then [lambda {dir url http_state} {
- save_file $dir $url [dict get $http_state body]
- } /tmp $url]
- }]
- lappend promises [pexec du -sk /tmp]; # Single line added
- set gate [all $promises]
- $gate done print_done