diff options
Diffstat (limited to 'core/examples/http_bench.rs')
-rw-r--r-- | core/examples/http_bench.rs | 108 |
1 files changed, 51 insertions, 57 deletions
diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index ea8058019..3e02cdd46 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -111,62 +111,54 @@ fn test_record_from() { pub type HttpBenchOp = dyn Future<Item = i32, Error = std::io::Error> + Send; -struct HttpBench(); - -impl Dispatch for HttpBench { - fn dispatch( - &mut self, - control: &[u8], - zero_copy_buf: deno_buf, - ) -> (bool, Box<Op>) { - let record = Record::from(control); - let is_sync = record.promise_id == 0; - let http_bench_op = match record.op_id { - OP_LISTEN => { - assert!(is_sync); - op_listen() - } - OP_CLOSE => { - assert!(is_sync); - let rid = record.arg; - op_close(rid) - } - OP_ACCEPT => { - assert!(!is_sync); - let listener_rid = record.arg; - op_accept(listener_rid) - } - OP_READ => { - assert!(!is_sync); - let rid = record.arg; - op_read(rid, zero_copy_buf) - } - OP_WRITE => { - assert!(!is_sync); - let rid = record.arg; - op_write(rid, zero_copy_buf) - } - _ => panic!("bad op {}", record.op_id), - }; - let mut record_a = record.clone(); - let mut record_b = record.clone(); - - let op = Box::new( - http_bench_op - .and_then(move |result| { - record_a.result = result; - Ok(record_a) - }).or_else(|err| -> Result<Record, ()> { - eprintln!("unexpected err {}", err); - record_b.result = -1; - Ok(record_b) - }).then(|result| -> Result<Buf, ()> { - let record = result.unwrap(); - Ok(record.into()) - }), - ); - (is_sync, op) - } +fn dispatch(control: &[u8], zero_copy_buf: deno_buf) -> (bool, Box<Op>) { + let record = Record::from(control); + let is_sync = record.promise_id == 0; + let http_bench_op = match record.op_id { + OP_LISTEN => { + assert!(is_sync); + op_listen() + } + OP_CLOSE => { + assert!(is_sync); + let rid = record.arg; + op_close(rid) + } + OP_ACCEPT => { + assert!(!is_sync); + let listener_rid = record.arg; + op_accept(listener_rid) + } + OP_READ => { + assert!(!is_sync); + let rid = record.arg; + op_read(rid, zero_copy_buf) + } + OP_WRITE => { + assert!(!is_sync); + let rid = record.arg; + op_write(rid, zero_copy_buf) + } + _ => panic!("bad op {}", record.op_id), + }; + let mut record_a = record.clone(); + let mut record_b = record.clone(); + + let op = Box::new( + http_bench_op + .and_then(move |result| { + record_a.result = result; + Ok(record_a) + }).or_else(|err| -> Result<Record, ()> { + eprintln!("unexpected err {}", err); + record_b.result = -1; + Ok(record_b) + }).then(|result| -> Result<Buf, ()> { + let record = result.unwrap(); + Ok(record.into()) + }), + ); + (is_sync, op) } fn main() { @@ -182,7 +174,9 @@ fn main() { filename: "http_bench.js", }); - let isolate = deno::Isolate::new(startup_data, HttpBench()); + let mut config = deno::Config::default(); + config.dispatch(dispatch); + let isolate = deno::Isolate::new(startup_data, config); isolate.then(|r| { js_check(r); |