# Pastebin z1N7ziCH
diff --git a/htmlify.p6 b/htmlify.p6
--- a/htmlify.p6
+++ b/htmlify.p6
@@ -31,6 +31,25 @@ use Pod::Htmlify;
use experimental :cached;
+use NativeCall;
+sub fork returns int32 is native { * };
+CATCH {
+ when X::AdHoc {
+ sub fork() {
+ return -1;
+ }
+ }
+};
+sub waitpid(int32, int32 is rw, int32) returns int32 is native { * };
+CATCH {
+ when X::AdHoc {
+ sub waitpid() {
+ return -1;
+ }
+ }
+};
+const $WNOHANG = 1;
+
my $type-graph;
my %routines-by-type;
@@ -132,11 +151,29 @@ sub MAIN(
say 'Composing doc registry ...';
$*DR.compose;
+ my %children = ();
for $*DR.lookup("language", :by).list -> $doc {
say "Writing language document for {$doc.name} ...";
my $pod-path = pod-path-from-url($doc.url);
+
+ my $pid = fork();
+ if ($pid > 0) { # parent
+ %children[$pid] = 1;
+ continue;
+ }
+ # Either we're a child or we can't fork
spurt "html{$doc.url}.html",
p2h($doc.pod, 'language', pod-path => $pod-path);
+ if ($pid == 0) { # child
+ exit 0;
+ }
+ }
+ while (%children) {
+ for $pid (keys %children) {
+ my int32 $status;
+ my $rv = waitpid($pid, $status, $WNOHANG);
+ %children{$pid}.delete if $rv == $pid;
+ }
}
for $*DR.lookup("type", :by).list {
write-type-source $_;