Guest User

Is there a better version to remove the extra control?

a guest
Aug 7th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!env raku
  2.  
  3. my Channel $channel-job-notifier .= new;
  4. my Channel $channel .= new;
  5.  
  6. my @p = do for 0 .. 2 -> $idx {
  7. start {
  8. loop {
  9. last
  10. if $channel.closed;
  11. my $d = try { $channel.receive } // last;
  12.  
  13. $channel-job-notifier.send(("$idx", $d));
  14.  
  15. my @args = (3);
  16. if $idx == 2 {
  17. @args = (10);
  18. }
  19.  
  20. my $proc = Proc::Async.new: 'sleep', |@args;
  21.  
  22. $proc.stdout.lines.tap(-> $v {
  23. # $output-fp.IO.spurt: "$v\n", :append;
  24. });
  25.  
  26. await $proc.start;
  27. }
  28. };
  29. }
  30.  
  31. for dir('./test/') -> $d is copy {
  32. $channel.send($d);
  33.  
  34. my ($idx, $d-processing) = $channel-job-notifier.receive;
  35.  
  36. "Start processing $d".say;
  37. }
  38.  
  39. $channel.close;
  40.  
  41. await @p;
  42.  
Advertisement
Add Comment
Please, Sign In to add comment