diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-09-24 22:46:36 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-25 17:02:49 -0400 |
commit | b088b58f7664cbb2fcb1e12f8aa439d377f56d49 (patch) | |
tree | a3cd8a4e40e06c55c76d3465b4e11b8b85b88abb /js | |
parent | 4fd2b19f640d19e57511eb142b63e16c879ef6fd (diff) |
Add SetGlobalTimeout().
To be used for a timers implementation soon.
Diffstat (limited to 'js')
-rw-r--r-- | js/deno.ts | 1 | ||||
-rw-r--r-- | js/timers.ts | 9 | ||||
-rw-r--r-- | js/timers_test.ts | 5 |
3 files changed, 15 insertions, 0 deletions
diff --git a/js/deno.ts b/js/deno.ts index 3bbda69e8..92ba5301d 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -15,4 +15,5 @@ export { ErrorKind, DenoError } from "./errors"; export { libdeno } from "./libdeno"; export { arch, platform } from "./platform"; export { trace } from "./trace"; +export { setGlobalTimeout } from "./timers"; export const args: string[] = []; diff --git a/js/timers.ts b/js/timers.ts index 42be96d91..03badfd46 100644 --- a/js/timers.ts +++ b/js/timers.ts @@ -19,6 +19,15 @@ interface Timer { delay: number; // milliseconds } +export function setGlobalTimeout(timeout: number) { + const builder = new flatbuffers.Builder(); + fbs.SetTimeout.startSetTimeout(builder); + fbs.SetTimeout.addTimeout(builder, timeout); + const msg = fbs.SetTimeout.endSetTimeout(builder); + const res = sendSync(builder, fbs.Any.SetTimeout, msg); + assert(res == null); +} + function startTimer( id: number, cb: TimerCallback, diff --git a/js/timers_test.ts b/js/timers_test.ts index af172e976..e5fe2d478 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -1,4 +1,5 @@ import { test, assertEqual } from "./test_util.ts"; +import { setGlobalTimeout } from "deno"; function deferred() { let resolve; @@ -95,3 +96,7 @@ test(async function intervalCancelInvalidSilentFail() { // Should silently fail (no panic) clearInterval(2147483647); }); + +test(async function SetGlobalTimeoutSmoke() { + setGlobalTimeout(50); +}); |