Library
Module
Module type
Parameter
Class
Class type
Tasks to be performed within Commands
type http_error = [
| `Http_status of int
| `Http_no_json
Resource is not a valid json file
*)| `Http_decode
Resource is a valid json file, but the decoder could not decode the corresponding javascript object.
*) ]
val succeed : 'a -> ('a, 'e) t
val return : 'a -> ('a, 'e) t
val fail : 'e -> ('a, 'e) t
val log_string : string -> (unit, 'e) t
log_string str
Write str
to the console.
send_to_javascript value
Send the javascript object value
to the surrounding javascript world.
val sleep : int -> 'a -> ('a, 'e) t
sleep millis a
Sleep for millis
milliseconds and then return a
.
Examples:
let* _ = sleep 1000 () in (* sleep 1000 milliseconds *)
task (* and then execute [task] *)
let* a = task1 >>= sleep 1000 (* excute [task1] and return result
[a] after 1000 milliseconds *)
in
task2 a (* then execute [task2 a] *)
val next_tick : 'a -> ('a, 'e) t
next_tick a
Return a
in the next tick of the event loop.
Example: Execute task
in the next round of the event loop.
let* _ = next_tick () in
task
val time_zone : (Time.Zone.t, 'e) t
Get the current time zone.
random ran
Execute the random generator rand
and return the generated random value.
val http_text :
string ->
string ->
(string * string) list ->
string ->
(string, http_error) t
http_text method url headers body
Make a http method
request to url
with headers
and body
. Expect the response as a string.
Method is one of GET, POST, DELETE, ...
.
Then headers and the body can be empty.
val http_json :
string ->
string ->
(string * string) list ->
string ->
'a Decoder.t ->
('a, http_error) t