fn cpu_run<'a>(req: &mut Request, response: Response<'a>) -> MiddlewareResult<'a> {
	let id = req.param("id").parse::<i32>().ok().expect("unable to run invalid cpu id");
	
	match req.extensions().get::<CpuDb>() {
		Some(cpuserv) => {
			let mut cycles = 0i32;
			let mut w_serv = cpuserv.write().unwrap();
			let cpu = w_serv.database.get_mut(&id).unwrap();
			cpu.last = cpu.state;

			loop {
				if cycles >= MAX_CYCLES { println!("CPU executed > {} cycles.", MAX_CYCLES); break; }
				cycles += 1;

				match cpu.state.tick() {
					CpuState::Halt => { break; },
					CpuState::Continue => { continue; },
				}
			}

			response.send(format!("{}", cpu.state.js_dump()))
		},
		None => { response.send("did not find cpu serv") }
	}
}
/// POST /cpu/:id/run
/// Resumes execution from the next instruction; running the machine to completion.
/// The resultant state is then dumped to the console.
POST /cpu/:id/run
Resumes execution from the next instruction; running the machine to completion.
The resultant state is then dumped to the console.
POST / cpu / : id / run Resumes execution from the next instruction ; running the machine to completion . The resultant state is then dumped to the console .
fn cpu_run<'a>(req: &mut Request, response: Response<'a>) -> MiddlewareResult<'a> {
	let id = req.param("id").parse::<i32>().ok().expect("unable to run invalid cpu id");
	match req.extensions().get::<CpuDb>() {
		Some(cpuserv) => {
			let mut cycles = 0i32;
			let mut w_serv = cpuserv.write().unwrap();
			let cpu = w_serv.database.get_mut(&id).unwrap();
			cpu.last = cpu.state;
			loop {
				if cycles >= MAX_CYCLES { println!("CPU executed > {} cycles.", MAX_CYCLES); break; }
				cycles += 1;
				match cpu.state.tick() {
					CpuState::Halt => { break; },
					CpuState::Continue => { continue; },
				}
			}
			response.send(format!("{}", cpu.state.js_dump()))
		},
		None => { response.send("did not find cpu serv") }
	}
}
fn cpu_run < ' a > ( req : & mut Request , response : Response < ' a > ) -> MiddlewareResult < ' a > { let id = req . param ( " " ) . parse :: < i32 > ( ) . ok ( ) . expect ( " " ) ; match req . extensions ( ) . get :: < CpuDb > ( ) { Some ( cpuserv ) => { let mut cycles = 0i32 ; let mut w_serv = cpuserv . write ( ) . unwrap ( ) ; let cpu = w_serv . database . get_mut ( & id ) . unwrap ( ) ; cpu . last = cpu . state ; loop { if cycles >= MAX_CYCLES { println ! ( " " MAX_CYCLES ) ; break ; } cycles += 1 ; match cpu . state . tick ( ) { CpuState :: Halt => { break ; } , CpuState :: Continue => { continue ; } , } } response . send ( format ! ( " " cpu state js_dump ( ) ) ) } , None => { response . send ( " " ) } } }
POST /cpu/:id/run
Resumes execution from the next instruction; running the machine to completion.
POST / cpu / : id / run Resumes execution from the next instruction ; running the machine to completion .
req
&mut Request
response
Response<'a>