/*---------------------------------------------------------------------------
  Copyright 2026, Tim Whiting, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/
module uv/evloopstd/async/api/uv/evloop

import std/num/int64std/num/int64

extern import
  c[host=libc] { vcpkg="libuv"; library="uv" }

extern import
  c[host=libc,os=windows] { syslib="user32;iphlpapi;userenv;ws2_32;dbghelp;ole32;uuid" }

extern import
  c { header-file="evloop.h"; file="evloop.c" }

extern import
  c  file "evloop-timer.c"
  js file "evloop-timer.js"

pub extern event-loop-initstd/async/api/uv/evloop/event-loop-init: () -> any() : anystd/core/types/any: V
  c "kk_uv_loop_init"
  js inline "null"

pub extern event-loop-runstd/async/api/uv/evloop/event-loop-run: (evloop : any) -> ()(evloopevloop: any : anystd/core/types/any: V) : (std/core/types/unit: V)std/core/types/unit: V
  c "kk_uv_loop_run"
  js inline "$std_core_types.Unit"

pub extern timer-setupstd/async/api/uv/evloop/timer-setup: (evloop : any, millisecs : int64, cb : () -> ioc ()) -> ioc error<() -> ioc ()>( evloopevloop: any : anystd/core/types/any: V, millisecsmillisecs: int64 : int64std/core/types/int64: V, cbcb: () -> ioc () : () -> iocstd/core/ioc: E (std/core/types/unit: V)std/core/types/unit: V ) : iocstd/core/ioc: E errorstd/core/exn/error: V -> V<() -> iocstd/core/ioc: E (std/core/types/unit: V)std/core/types/unit: V>
  c  "kk_timer_setup"
  js "kk_timer_setup"

pub extern immediate-setupstd/async/api/uv/evloop/immediate-setup: (evloop : any, cb : () -> ioc ()) -> ioc error<() -> ioc ()>( evloopevloop: any : anystd/core/types/any: V, cbcb: () -> ioc () : () -> iocstd/core/ioc: E (std/core/types/unit: V)std/core/types/unit: V ) : iocstd/core/ioc: E errorstd/core/exn/error: V -> V<() -> iocstd/core/ioc: E (std/core/types/unit: V)std/core/types/unit: V>
  c  "kk_immediate_setup"
  js "kk_immediate_setup"