<commit_before># Anything that can be subscribed to does this role. It provides the basic
# supply management infrastructure, as well as various coercions that
# turn Supply-like things into something else and convenience forms of calls
# to SupplyOperations.

my class SupplyOperations { ... }

my class Tap {
    has &.more;
    has &.done;
    has &.quit;
    has &.closing;
    has $.supply;

    method close { $!supply.close(self) }
}

my role Supply {
    has @!tappers;
    has $!tappers_lock = Lock.new;

    method tap(&more = -> $ { }, :&done, :&quit = {die $_}, :&closing) {
        my $sub = Tap.new(:&more, :&done, :&quit, :&closing, :supply(self));
        $!tappers_lock.protect({
            @!tappers.push($sub);
        });
        $sub
    }

    method close(Tap $t) {
        $!tappers_lock.protect({
            @!tappers .= grep(* !=== $t);
        });
        if $t.closing -> &closing {
            closing();
        }
    }
<commit_msg>Make (Supply|Tap).close return True on success<commit_after># Anything that can be subscribed to does this role. It provides the basic
# supply management infrastructure, as well as various coercions that
# turn Supply-like things into something else and convenience forms of calls
# to SupplyOperations.

my class SupplyOperations { ... }

my class Tap {
    has &.more;
    has &.done;
    has &.quit;
    has &.closing;
    has $.supply;

    method close { $!supply.close(self) }
}

my role Supply {
    has @!tappers;
    has $!tappers_lock = Lock.new;

    method tap(&more = -> $ { }, :&done, :&quit = {die $_}, :&closing) {
        my $sub = Tap.new(:&more, :&done, :&quit, :&closing, :supply(self));
        $!tappers_lock.protect({
            @!tappers.push($sub);
        });
        $sub
    }

    method close(Tap $t) {
        my $found;
        $!tappers_lock.protect({
            @!tappers .= grep( { $_ === $t ?? !($found = True) !! True } );
        });
        if $t.closing -> &closing {
            closing();
        }
        $found // False;
    }

{'fraction_non_alphanumeric': 0.15301618440411965, 'fraction_numerical': 0.0, 'mean_word_length': 2.2278481012658227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7347471', 'n_tokens_mistral': 689, 'n_tokens_neox': 650, 'n_words': 192}