<commit_before>extern mod extra;
use std::task::spawn;
use std::comm::{stream,Chan,Port};
use std::cell::Cell;

fn generate(ch: &Chan<int>) {
    let mut i = 2;
    loop {
        ch.send(i);
        i = i + 1;
    }
}

fn filter(in_ch: &Port<int>, out_ch: &Chan<int>, prime: int) {
    loop {
        let i = in_ch.recv();
        if i % prime != 0 {
            out_ch.send(i);
        }
    }
}

fn main() {
    let (port, chan) = stream();

    let mut prev_port = port;

    do spawn {
        generate(&chan);
    }

    loop {
        let prime = prev_port.recv();
        println!("{}", prime);

        let (new_port, new_chan) = stream();
        let prev_port_cell = Cell::new(prev_port);

        do spawn {
            filter(&prev_port_cell.take(), &new_chan, prime);
        }
        prev_port = new_port;
    }
}<commit_msg>Implement most of the fixes from @tikue<commit_after>extern mod extra;
use std::task::spawn_with;
use extra::comm::{SyncPort, SyncChan, rendezvous};
use std::iter::count;

fn generate(ch: SyncChan<int>) {
    for i in count(2, 1) {
        if !ch.try_send(i) {
            break;
        }
    }
}

fn filter(in_ch: SyncPort<int>, out_ch: SyncChan<int>, prime: int) {
    loop {
        let i = in_ch.recv();
        if i % prime != 0 {
            out_ch.send(i);
        }
    }
}

fn main() {
    let (port, chan) = rendezvous();

    let mut prev_port = port;

    do spawn_with(chan) |chan| {
        generate(chan);
    }

    loop {
        let prime = prev_port.recv();
        println!("{}", prime);

        let (new_port, new_chan) = rendezvous();

        do spawn_with((prev_port, new_chan)) |(prev_port, new_chan)| {
            filter(prev_port, new_chan, prime);
        }
        prev_port = new_port;
    }
}
{'fraction_non_alphanumeric': 0.15336728919071874, 'fraction_numerical': 0.003395585738539898, 'mean_word_length': 2.0801393728222997, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5962519', 'n_tokens_mistral': 655, 'n_tokens_neox': 627, 'n_words': 148}