Documentation for method on-switch
assembled from the following pages:
Class: IO::CatHandle §
From IO::CatHandle
(IO::CatHandle) method on-switch §
Defined as:
has is rw
One of the attributes that can be set during .new
call and changed later by assigning to. By default is not specified. Takes a Callable with .count
of 0
, 1
, 2
, or Inf
. Gets called every time .next-handle
is, which happens once during .new
call and then each time a source handle is switched to the next one in the queue, or when the .next-handle
method is called manually.
If the .count
of &.on-switch
is 0
, it receives no arguments; if it's 1
, it receives the currently active handle, and if it's 2
or Inf
, it receives the currently active handle, and the last active handle as positional arguments (in that order). On the very first &.on-switch
execution, the "last active handle" argument is Nil
. Upon source handle queue exhaustion the "currently active handle" argument is Nil
, and all the executions made afterwards have both arguments as Nil
.
(my = 'foo'.IO).spurt: "A\nB\nC";(my = 'bar'.IO).spurt: "D\nE"; my ;my = IO::CatHandle.new: :on-switch, , ;say ": $_" for .lines;# OUTPUT: # foo:1 A # foo:2 B # foo:3 C # bar:1 D # bar:2 E
my ;sub on-switch (, ) (my = 'foo'.IO).spurt: "A\nB\nC";(my = 'bar'.IO).spurt: "D\nE";my = IO::CatHandle.new: :, , ;.lines.raku.say; # OUTPUT: «("", "B", "C", "", "E").Seq» .raku.say; # OUTPUT: «["A\nB\nC", "D\nE"]»