Skip to content

Instantly share code, notes, and snippets.

View gterzian's full-sized avatar

Gregory Terzian gterzian

View GitHub Profile
// Our "consumer", who is passed a "chan", which is the "consumer chan"
// the main thread shared with it to send results on back to the main thread.
// It also returns a "consumer chan", which is the sender that is shared with each worker.
fn start_consumer(chan: Sender<ConsumerControlMsg>,
number_of_workflows: usize,
number_of_steps: usize)
-> Sender<ConsumerMsg> {
// The consumer chan, sender will be shared with each worker.
let (consumer_chan, consumer_port) = channel();
loop {
// "msg" is the result of the "select" above...
let result = match msg {
MainMsg::FromProducer(ProducerMsg::Incoming(workflow)) => {
// Distribute the work among workers...
// then continue...
continue;
},
MainMsg::FromConsumer(msg) => msg
};
struct WorkflowExecutor {
executions: VecDeque<(Workflow, WorkflowExecution)>,
port: Receiver<ExecutorMsg>,
chan: Sender<ConsumerMsg>
}
impl WorkflowExecutor {
fn handle_a_msg(&mut self) -> bool {
match self.port.try_recv() {
Ok(ExecutorMsg::Execute(workflow)) => {
// Our "consumer", is shared with a "chan", which is the "consumer chan",
// the main thread shared with it, to send results on back to the main thread.
// It also returns a "consumer chan", which is the sender that is shared with each worker.
fn start_consumer(chan: Sender<ConsumerControlMsg>,
number_of_workflows: usize,
number_of_steps: usize)
-> Sender<ConsumerMsg> {
// The consumer chan, sender will be shared with each worker.
let (consumer_chan, consumer_port) = channel();
struct ExecutorControlChan {
id: ExecutorId,
chan: Sender<(ExecutorId, ExecutorControlMsg)>
}
impl ExecutorControlChan {
fn send(&self, msg: ExecutorControlMsg) {
let _ = self.chan.send((self.id, msg));
}
}
fn start_executor(chan: Sender<ConsumerMsg>) -> Sender<ExecutorMsg> {
let (executor_chan, executor_port) = channel();
let _ = thread::Builder::new().spawn(move || {
let mut executor = WorkflowExecutor {
executions: Default::default(),
port: executor_port,
chan: chan,
};
while executor.run() {
// Running...
enum PipelineMsg {
Generated(u8),
Squared(u8),
Merged(u8),
}
fn square(merge_chan: Sender<PipelineMsg>) -> Sender<PipelineMsg> {
let (chan, port) = channel();
let _ = thread::Builder::new().spawn(move || {
for msg in port {
// Check that the msg is of the expected variant.
let num = match msg {
PipelineMsg::Generated(num) => num,
_ => panic!("unexpected message receiving at square stage"),
};
// Send a message of the variant corresponding to the next stage.
/// The key used to differentiate requests in the cache.
#[derive(Clone, Eq, Hash, MallocSizeOf, PartialEq )]
pub struct CacheKey {
url: ServoUrl
}
/// A complete cached resource.
#[derive(Clone)]
struct CachedResource {
request_headers: Arc<Mutex<Headers>>,
pub struct HttpState {
pub hsts_list: RwLock<HstsList>,
pub cookie_jar: RwLock<CookieStorage>,
pub http_cache: RwLock<HttpCache>,
pub auth_cache: RwLock<AuthCache>,
pub history_states: RwLock<HashMap<HistoryStateId, Vec<u8>>>,
pub ssl_client: OpensslClient,
pub connector: Pool<Connector>,
}