Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
Soremwar committed Dec 5, 2020
1 parent bc53a3b commit 39f2ee9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
13 changes: 4 additions & 9 deletions cli/ops/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
use std::cell::RefCell;
use std::{cell::RefCell};
use std::future::Future;
use std::pin::Pin;
use std::rc::Rc;
Expand Down Expand Up @@ -146,7 +146,7 @@ fn op_now(
// Arguments are discarded
_sync: bool,
_x: i32,
zero_copy: BufVec,
mut zero_copy: BufVec,
) -> MinimalOp {
match zero_copy.len() {
0 => return MinimalOp::Sync(Err(type_error("no buffer specified"))),
Expand All @@ -168,15 +168,10 @@ fn op_now(
}

let result = (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000 as f64);
println!("{}", &result);

let mut x = Vec::from(&*zero_copy[0]);
(&mut zero_copy[0]).copy_from_slice(&result.to_be_bytes());

println!("{}", x.len());

x.clone_from_slice(&result.to_be_bytes());

MinimalOp::Sync(Ok(1))
MinimalOp::Sync(Ok(0))
}

#[derive(Deserialize)]
Expand Down
10 changes: 7 additions & 3 deletions cli/rt/11_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
await core.jsonOpAsync("op_global_timer");
}

const now = new Uint8Array;
const nowBytes = new Uint8Array(8);
function opNow(x) {
sendSync("op_now", x, now);
return now;
sendSync("op_now", x, nowBytes);
return new DataView(
Uint8Array.from(nowBytes).buffer,
0
)
.getFloat64();
}

function sleepSync(millis = 0) {
Expand Down
3 changes: 1 addition & 2 deletions cli/rt/40_performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
}

function now() {
const a = opNow(0);
console.log(a);
return opNow(0);
}

class PerformanceEntry {
Expand Down

0 comments on commit 39f2ee9

Please sign in to comment.