1///|
2type Loop 
Bytes
Bytes
3 4///| 5extern "c" fn uv_loop_make() ->
type Loop Bytes
Loop
= "moonbit_uv_loop_make"
6 7///| 8extern "c" fn uv_loop_init(loop_ :
type Loop Bytes
Loop
) ->
Int
Int
= "moonbit_uv_loop_init"
9 10///| 11pub fn
type Loop Bytes
Loop
::
() -> Loop!Errno
new
() ->
type Loop Bytes
Loop
!
type! Errno Status
Errno
{
12 let
Loop
loop_
=
() -> Loop
uv_loop_make
()
13 let
Int
status
=
(loop_ : Loop) -> Int
uv_loop_init
(
Loop
loop_
)
14 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
15 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
)
16 } 17 return
Loop
loop_
18} 19 20///| 21extern "c" fn uv_loop_close(loop_ :
type Loop Bytes
Loop
) ->
Int
Int
= "moonbit_uv_loop_close"
22 23///| 24pub fn
type Loop Bytes
Loop
::
(loop_ : Loop) -> Unit!Errno
close
(
Loop
loop_
:
type Loop Bytes
Loop
) ->
Unit
Unit
!
type! Errno Status
Errno
{
25 let
Int
status
=
(loop_ : Loop) -> Int
uv_loop_close
(
Loop
loop_
)
26 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
27 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
)
28 } 29} 30 31///| 32pub(all) enum RunMode { 33
RunMode
Default
= 0
34
RunMode
Once
= 1
35
RunMode
NoWait
= 2
36} 37 38///| 39extern "c" fn uv_run(uv :
type Loop Bytes
Loop
, mode :
enum RunMode {
  Default
  Once
  NoWait
}
RunMode
) ->
Int
Int
= "moonbit_uv_run"
40 41///| 42pub fn
(self : Loop, mode : RunMode) -> Unit!Errno
run
(
Loop
self
:
type Loop Bytes
Loop
,
RunMode
mode
:
enum RunMode {
  Default
  Once
  NoWait
}
RunMode
) ->
Unit
Unit
!
type! Errno Status
Errno
{
43 let
Int
status
=
(uv : Loop, mode : RunMode) -> Int
uv_run
(
Loop
self
,
RunMode
mode
)
44 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
45 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
)
46 } 47} 48 49///| 50extern "c" fn uv_stop(loop_ :
type Loop Bytes
Loop
) = "moonbit_uv_stop"
51 52///| 53pub fn
(self : Loop) -> Unit
stop
(
Loop
self
:
type Loop Bytes
Loop
) ->
Unit
Unit
{
54
(loop_ : Loop) -> Unit
uv_stop
(
Loop
self
)
55} 56 57///| 58extern "c" fn uv_loop_alive(loop_ :
type Loop Bytes
Loop
) ->
Int
Int
= "moonbit_uv_loop_alive"
59 60///| 61pub fn
type Loop Bytes
Loop
::
(loop_ : Loop) -> Bool
alive
(
Loop
loop_
:
type Loop Bytes
Loop
) ->
Bool
Bool
{
62 return
(loop_ : Loop) -> Int
uv_loop_alive
(
Loop
loop_
)
(x : Int, y : Int) -> Bool
!=
0
63} 64