Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created November 30, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/d57a7018b2bf1c3863f37098ef24fd75 to your computer and use it in GitHub Desktop.
Save Xliff/d57a7018b2bf1c3863f37098ef24fd75 to your computer and use it in GitHub Desktop.
Wrappity Wrap
sub create-signal-supply (%sigs, $signal, $s) is export {
  my $supply = $s.Supply;
  $supply.^lookup('tap').wrap: my method (|c) {
    %sigs{$signal} = True;
    # cw: Wrap on the Callable in |c to add the default
    #     exception handler.
    if c.list[0] ~~ Callable {
      my $wrapped = sub (|a) {
        CATCH { default { .message.say; .backtrace.concise.say } }
        c.list[0](|a);
      }
      nextwith($wrapped, |c.hash)
    } else {
      nextsame;
    }
  };
  $supply
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment