<commit_before>module Threads;

class Task {
    has Mu $!task;
    has $.code;

    method schedule {
        my Mu $do := nqp::getattr(
            pir::perl6_decontainerize__PP($!code), Code, '$!do'
        );
        my Mu $task := pir::new__PSP('Task', $do);
        nqp::bindattr(self, Task, '$!task', $task);
        pir::schedule__0P($task);
    }

    method join {
        pir::wait__0P($!task);
    }
}

sub async(&code) is export {
    my $wrapper = sub (Mu) {
        &code()
    };

    my $t = Task.new(code => $wrapper);

    $t.schedule;

    return $t;
}
<commit_msg>Make async() code more compact<commit_after>module Threads;

class Task {
    has Mu $!task;
    has $.code;

    method schedule {
        my Mu $do := nqp::getattr(
            pir::perl6_decontainerize__PP($!code), Code, '$!do'
        );
        my Mu $task := pir::new__PSP('Task', $do);
        nqp::bindattr(self, Task, '$!task', $task);
        pir::schedule__0P($task);

        return self; # allow chaining
    }

    method join {
        pir::wait__0P($!task);
    }
}

sub async(&code) is export {
    my $wrapper = sub (Mu) {
        &code()
    };

    return Task.new(code => $wrapper).schedule
}

{'fraction_non_alphanumeric': 0.16930775646371976, 'fraction_numerical': 0.0050041701417848205, 'mean_word_length': 2.2085561497326203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2679344', 'n_tokens_mistral': 427, 'n_tokens_neox': 415, 'n_words': 98}