Skip to content

Commit

Permalink
Add array of block with with
Browse files Browse the repository at this point in the history
  • Loading branch information
FCO committed Sep 22, 2019
1 parent d8c5aa1 commit 17dd42d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/Red/Do.pm6
Expand Up @@ -105,16 +105,23 @@ proto red-do(|) {

#| Receives a block and optionally a connection name.
#| Runs the block with the connection with that name
multi red-do(&block, Str :$with = "default", :$async) is export {
multi red-do(*@blocks where .all ~~ Callable, Str :$with = "default", :$async) is export {
X::Red::Do::DriverNotDefined.new(:driver($with)).throw unless %GLOBAL::RED-DEFULT-DRIVERS{$with}:exists;
red-do :with(%GLOBAL::RED-DEFULT-DRIVERS{$with}), &block, :$async;
my @ret = do for @blocks {
red-do :with(%GLOBAL::RED-DEFULT-DRIVERS{$with}), $_, :$async
}
if $async {
return start await @ret
}
return @ret.head if @ret == 1;
@ret
}


#| Receives a block and optionally a connection name.
#| Runs the block with the connection with that name
#| synchronously
multi red-do(&block, Red::Driver:D :$with = "default", :$async where not *) is export {
multi red-do(&block, Red::Driver:D :$with, :$async where not *) is export {
run-red-do $with, &block
}

Expand Down

0 comments on commit 17dd42d

Please sign in to comment.