Spinning up sort
My Linux box is transcoding from mp4 to av1 like a boss. I figured that shrinking the space hogs to halve is cheaper then doubling disk space. Running with a load of 20.29 for a few days helped to uncover a bug and a ENODOCish.
I wanted the following code to DWIM.
my $obj = class AnonClass {
has @.a;
method push(\e) { self.a.push: e; self }
method list { self.a.list }
}.new;
my $sort = Proc::Async.new('/usr/bin/sort');
{ (‚a‘..‚z‘).roll(10) } |> $sort |> $obj;
Have a block that returns a list (that’s the small one that might be lazy) and feed it’s values into sort
. Not overly helpful to have a blocking shell command with a lazy list but blocking did help to uncover a thinko of mine before. The result is then fed into something I call an Arrayish
, a not-quite-type defined by a subset.
subset Arrayish of Any where { .^can(‚push‘) && .^can(‚list‘) }
Used in a Signature it basicly means: “If you give me an object that got .push
and .list
with the semantics of the buildin types, I will gladly take it.” The pipe operator handling this case looks as follows.
my multi infix:«|>»(Arrayish:D \a, Proc::Async:D $in) {
my $pipe = Shell::Pipe.new;
$pipe.pipees.push: a;
$pipe.pipees.push: $in;
# FIXME workaround R#3778
$in.^attributes.grep(*.name eq '$!w')[0].set_value($in, True);
$pipe.starters.push: -> {
| $in.start, start {
LEAVE try $in.close-stdin;
await $in.ready;
$in.write: „$_\n“.encode for a.list;
}
}
$pipe
}
At first I did not have the blocking await $in.ready
what caused the block to spit text in the direction of sort
before the latter was properly started and ready to read on its STDIN. The docs mention .write
and .ready
but don’t explain that you need to use them together. If my system would have been idle I might not have spotted it. So I can conclude that porn is useful, so long as it is made smaller. A surprising thought because it’s usually used to make things bigger.
If you are using async behaviour it might help to run stress -c 32
in the background to push your heisenbugs over the edge. While you are on it, please push my bug over the edge too. I don’t really want to have them.
-
July 24, 2020 at 09:35Awaiting a bugfix | Playing Perl 6␛b6xA Raku