Aurel Bílý 6 vuotta sitten
vanhempi
commit
141c67f788
3 muutettua tiedostoa jossa 9 lisäystä ja 6 poistoa
  1. 1 1
      libs/uv/uv.ml
  2. 5 3
      libs/uv/uv_stubs.c
  3. 3 2
      src/macro/eval/evalStdLib.ml

+ 1 - 1
libs/uv/uv.ml

@@ -190,5 +190,5 @@ external dns_getaddrinfo : t_loop -> string -> bool -> bool -> int -> dns_gai_cb
 
 type timer_cb = unit -> unit
 
-external timer_start : t_loop -> int -> int -> timer_cb -> t_timer uv_result = "w_timer_start"
+external timer_start : t_loop -> int -> bool -> timer_cb -> t_timer uv_result = "w_timer_start"
 external timer_stop : t_timer -> unit_cb -> unit uv_result = "w_timer_stop"

+ 5 - 3
libs/uv/uv_stubs.c

@@ -785,17 +785,19 @@ static void handle_timer_cb(uv_timer_t *handle) {
 	CAMLreturn0;
 }
 
-CAMLprim value w_timer_start(value loop, value timeout, value repeat, value cb) {
-	CAMLparam4(loop, timeout, repeat, cb);
+CAMLprim value w_timer_start(value loop, value timeout, value persistent, value cb) {
+	CAMLparam4(loop, timeout, persistent, cb);
 	UV_ALLOC_CHECK(handle, uv_timer_t);
 	UV_ERROR_CHECK_C(uv_timer_init(Loop_val(loop), Timer_val(handle)), free(Timer_val(handle)));
 	UV_HANDLE_DATA(Timer_val(handle)) = alloc_data_timer(cb);
 	if (UV_HANDLE_DATA(Timer_val(handle)) == NULL)
 		UV_ERROR(0);
 	UV_ERROR_CHECK_C(
-		uv_timer_start(Timer_val(handle), handle_timer_cb, Int_val(timeout), Int_val(repeat)),
+		uv_timer_start(Timer_val(handle), handle_timer_cb, Int_val(timeout), Int_val(timeout)),
 		{ unalloc_data(UV_HANDLE_DATA(Timer_val(handle))); free(Timer_val(handle)); }
 		);
+	if (!Bool_val(persistent))
+		uv_unref(Handle_val(handle));
 	UV_SUCCESS(handle);
 }
 

+ 3 - 2
src/macro/eval/evalStdLib.ml

@@ -3510,9 +3510,10 @@ module StdUv = struct
 			| v -> unexpected_value v "UvTimer"
 		let new_ = (fun vl ->
 			match vl with
-				| [timeMs; cb] ->
+				| [timeMs; persistent; cb] ->
 					let timeMs = decode_int timeMs in
-					let handle = wrap_sync (Uv.timer_start (loop ()) timeMs timeMs (fun () ->
+					let persistent = decode_bool persistent in
+					let handle = wrap_sync (Uv.timer_start (loop ()) timeMs persistent (fun () ->
 						ignore (call_value cb [])
 						)) in
 					encode_instance key_eval_uv_Timer ~kind:(IUv (UvTimer handle))