module Js_global:sig
..end
window
in a browser context)type
intervalId
Js_global.setInterval
type
timeoutId
Js_global.setTimeout
val clearInterval : intervalId -> unit
(* API for a somewhat aggressive snoozing alarm clock *) let interval = Js.Undefined.empty let remind () = Js.log "Wake Up!"; IO.punchSleepyGuy () let snooze mins = interval := Js.Undefined.return @@ Js.Global.setInterval remind (mins * 60 * 1000) let cancel () = Js.Undefined.iter Js.Global.clearInterval !interval
val clearTimeout : timeoutId -> unit
(* A simple model of a code monkey's brain *) let timer = Js.Undefined.empty let work () = IO.closeHackerNewsTab () let procrastinate mins = Js.Undefined.iter fun Js.Global.clearTimeout !timer Js.Global.setTimeout work (mins * 60 * 1000)
val setInterval : (unit -> unit) -> int -> intervalId
returns an Js_global.intervalId
that can be passed to Js_global.clearInterval
to cancel the timeout
(* Will count up and print the count to the console every second *) let count = ref 0 let tick () = count := !count + 1; Js.log (string_of_int !count) let _ = Js.Global.setInterval tick 1000
val setTimeout : (unit -> unit) -> int -> timeoutId
returns a Js_global.timeoutId
that can be passed to Js_global.clearTimeout
to cancel the timeout
(* Prints "Timed out!" in the console after one second *) let message = "Timed out!" let _ = Js.Global.setTimeout (fun () -> Js.log message) 1000