1///|
2type Timer
3
4///|
5pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type Timer
Timer with to_handle(self : type Timer
Timer) -> type Handle
Handle = "%identity"
6
7///|
8pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type Timer
Timer with of_handle(self : type Handle
Handle) -> type Timer
Timer = "%identity"
9
10///|
11extern "c" fn uv_timer_make() -> type Timer
Timer = "moonbit_uv_timer_make"
12
13///|
14extern "c" fn uv_timer_init(uv : type Loop Bytes
Loop, timer : type Timer
Timer) -> Int
Int = "moonbit_uv_timer_init"
15
16///|
17pub fn type Timer
Timer::(self : Loop) -> Timer!Errno
new(Loop
self : type Loop Bytes
Loop) -> type Timer
Timer!type! Errno Status
Errno {
18 let Timer
timer = () -> Timer
uv_timer_make()
19 let Int
status = (uv : Loop, timer : Timer) -> Int
uv_timer_init(Loop
self, Timer
timer)
20 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
21 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
22 }
23 return Timer
timer
24}
25
26///|
27extern "c" fn uv_timer_start(
28 timer : type Timer
Timer,
29 cb : (type Timer
Timer) -> Unit
Unit,
30 // We shall never use Int/UInt for time, even in MoonBit.
31 timeout : UInt64
UInt64,
32 repeat : UInt64
UInt64
33) -> Int
Int = "moonbit_uv_timer_start"
34
35///|
36pub fn type Timer
Timer::(self : Timer, timeout~ : UInt64, repeat~ : UInt64, cb : (Timer) -> Unit) -> Unit!Errno
start(
37 Timer
self : type Timer
Timer,
38 UInt64
timeout~ : UInt64
UInt64,
39 UInt64
repeat~ : UInt64
UInt64,
40 (Timer) -> Unit
cb : (type Timer
Timer) -> Unit
Unit
41) -> Unit
Unit!type! Errno Status
Errno {
42 let Int
status = (timer : Timer, cb : (Timer) -> Unit, timeout : UInt64, repeat : UInt64) -> Int
uv_timer_start(Timer
self, (Timer) -> Unit
cb, UInt64
timeout, UInt64
repeat)
43 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
44 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
45 }
46}
47
48///|
49extern "c" fn uv_timer_stop(timer : type Timer
Timer) -> Int
Int = "moonbit_uv_timer_stop"
50
51///|
52pub fn type Timer
Timer::(self : Timer) -> Unit!Errno
stop(Timer
self : type Timer
Timer) -> Unit
Unit!type! Errno Status
Errno {
53 let Int
status = (timer : Timer) -> Int
uv_timer_stop(Timer
self)
54 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
55 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
56 }
57}
58
59///|
60extern "c" fn uv_timer_set_repeat(timer : type Timer
Timer, repeat : UInt64
UInt64) = "moonbit_uv_timer_set_repeat"
61
62///|
63pub fn type Timer
Timer::(self : Timer, repeat : UInt64) -> Unit
set_repeat(Timer
self : type Timer
Timer, UInt64
repeat : UInt64
UInt64) -> Unit
Unit {
64 (timer : Timer, repeat : UInt64) -> Unit
uv_timer_set_repeat(Timer
self, UInt64
repeat)
65}
66
67///|
68extern "c" fn uv_timer_get_repeat(timer : type Timer
Timer) -> UInt64
UInt64 = "moonbit_uv_timer_get_repeat"
69
70///|
71pub fn type Timer
Timer::(self : Timer) -> UInt64
get_repeat(Timer
self : type Timer
Timer) -> UInt64
UInt64 {
72 (timer : Timer) -> UInt64
uv_timer_get_repeat(Timer
self)
73}
74
75///|
76extern "c" fn uv_timer_get_due_in(timer : type Timer
Timer) -> UInt64
UInt64 = "moonbit_uv_timer_get_due_in"
77
78///|
79pub fn type Timer
Timer::(self : Timer) -> UInt64
get_due_in(Timer
self : type Timer
Timer) -> UInt64
UInt64 {
80 (timer : Timer) -> UInt64
uv_timer_get_due_in(Timer
self)
81}
82