<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! A task that sniffs data
use std::comm::{channel, Receiver, Sender, Disconnected};
use std::task::TaskBuilder;
use resource_task::{LoadResponse};

pub type SnifferTask = Sender<LoadResponse>;

pub fn new_sniffer_task(next_rx: Sender<LoadResponse>) -> SnifferTask {
  let(sen, rec) = channel();
  let builder = TaskBuilder::new().named("SnifferManager");
  builder.spawn(proc(){
    SnifferManager::new(rec).start(next_rx);
  });
  sen
}

struct SnifferManager {
  data_receiver: Receiver<LoadResponse>,
}

impl SnifferManager {
  fn new(data_receiver: Receiver <LoadResponse>) -> SnifferManager {
    SnifferManager {
      data_receiver: data_receiver,
    }
  }
}

impl SnifferManager {
  fn start(&self, next_rx: Sender<LoadResponse>) {
    loop {
      match self.data_receiver.try_recv() {
        Ok(snif_data) => next_rx.send(snif_data),
        Err(e) => {
          if e == Disconnected {
            break
          }
        }
      }
    }
  }
}<commit_msg>auto merge of #4017 : Ms2ger/servo/sniffertask, r=jdm<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! A task that sniffs data
use std::comm::{channel, Receiver, Sender, Disconnected};
use std::task::TaskBuilder;
use resource_task::{LoadResponse};

pub type SnifferTask = Sender<LoadResponse>;

pub fn new_sniffer_task(next_rx: Sender<LoadResponse>) -> SnifferTask {
    let (sen, rec) = channel();
    let builder = TaskBuilder::new().named("SnifferManager");
    builder.spawn(proc() {
        SnifferManager::new(rec).start(next_rx);
    });
    sen
}

struct SnifferManager {
    data_receiver: Receiver<LoadResponse>,
}

impl SnifferManager {
    fn new(data_receiver: Receiver<LoadResponse>) -> SnifferManager {
        SnifferManager {
            data_receiver: data_receiver,
        }
    }
}

impl SnifferManager {
    fn start(&self, next_rx: Sender<LoadResponse>) {
        loop {
            match self.data_receiver.try_recv() {
                Ok(snif_data) => next_rx.send(snif_data),
                Err(Disconnected) => break,
                Err(_) => (),
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.12530315278900567, 'fraction_numerical': 0.005254648342764754, 'mean_word_length': 3.077429983525535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, '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': '1758583', 'n_tokens_mistral': 805, 'n_tokens_neox': 792, 'n_words': 197}