1///|
2type Work
3
4///|
5extern "c" fn uv_work_make() -> type Work
Work = "moonbit_uv_work_make"
6
7///|
8extern "c" fn uv_queue_work(
9 uv : type Loop Bytes
Loop,
10 req : type Work
Work,
11 work_cb : (type Work
Work) -> Unit
Unit,
12 after_cb : (type Work
Work, Int
Int) -> Unit
Unit
13) -> Int
Int = "moonbit_uv_queue_work"
14
15///|
16pub fn (self : Loop, work_cb : (Work) -> Unit, after_cb : (Work) -> Unit, error_cb : (Work, Errno) -> Unit) -> Unit!Errno
queue_work(
17 Loop
self : type Loop Bytes
Loop,
18 (Work) -> Unit
work_cb : (type Work
Work) -> Unit
Unit,
19 (Work) -> Unit
after_cb : (type Work
Work) -> Unit
Unit,
20 (Work, Errno) -> Unit
error_cb : (type Work
Work, type! Errno Status
Errno) -> Unit
Unit
21) -> Unit
Unit!type! Errno Status
Errno {
22 let Work
req = () -> Work
uv_work_make()
23 let Int
status = (uv : Loop, req : Work, work_cb : (Work) -> Unit, after_cb : (Work, Int) -> Unit) -> Int
uv_queue_work(Loop
self, Work
req, fn(Work
req) { (Work) -> Unit
work_cb(Work
req) }, fn(
24 Work
req,
25 Int
status
26 ) {
27 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
28 (Work, Errno) -> Unit
error_cb(Work
req, type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status))
29 } else {
30 (Work) -> Unit
after_cb(Work
req)
31 }
32 })
33 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
34 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
35 }
36}
37