1// Copyright 2025 International Digital Economy Academy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15///|
16/// Handle for idle watchers in the libuv event loop.
17///
18/// Idle watchers run their callbacks once per event loop iteration, right before
19/// the event loop blocks for I/O. They are useful for performing background
20/// tasks when the event loop is idle.
21///
22/// Example:
23///
24/// ```moonbit
25/// let uv = @uv.Loop::new()
26/// let idle = @uv.Idle::new(uv)
27/// idle.start(fn(_) {
28/// println("Idle callback running")
29/// idle.stop() catch {
30/// error => println("Error stopping idle watcher: \{error}")
31/// }
32/// idle.close(_ => ())
33/// })
34/// uv.run(Default)
35/// uv.close()
36/// ```
37type Idle Bytes
Bytes
38
39///|
40pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle for type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle with to_handle(idle : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> type Handle
Handle = "%identity"
41
42///|
43pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
loop_(Self) -> Loop
}
ToHandle for type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle with of_handle(handle : type Handle
Handle) -> type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle = "%identity"
44
45///|
46extern "c" fn uv_idle_make() -> type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle = "moonbit_uv_idle_make"
47
48///|
49extern "c" fn uv_idle_init(uv : type Loop Bytes
Loop, idle : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> Int
Int = "moonbit_uv_idle_init"
50
51///|
52pub fn type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle::(self : Loop) -> Idle raise Errno
new(Loop
self : type Loop Bytes
Loop) -> type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle raise type! Errno Status
Errno {
53 let Idle
idle = () -> Idle
uv_idle_make()
54 let Int
status = (uv : Loop, idle : Idle) -> Int
uv_idle_init(Loop
self, Idle
idle)
55 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
56 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
57 }
58 return Idle
idle
59}
60
61///|
62extern "c" fn uv_idle_start(idle : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle, cb : (type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> Unit
Unit) -> Int
Int = "moonbit_uv_idle_start"
63
64///|
65extern "c" fn uv_idle_stop(idle : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> Int
Int = "moonbit_uv_idle_stop"
66
67///|
68pub fn type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle::(self : Idle, cb : (Idle) -> Unit) -> Unit raise Errno
start(Idle
self : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle, (Idle) -> Unit
cb : (type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> Unit
Unit) -> Unit
Unit raise type! Errno Status
Errno {
69 let Int
status = (idle : Idle, cb : (Idle) -> Unit) -> Int
uv_idle_start(Idle
self, fn(Idle
idle) { (Idle) -> Unit
cb(Idle
idle) })
70 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
71 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
72 }
73}
74
75///|
76pub fn type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle::(self : Idle) -> Unit raise Errno
stop(Idle
self : type Idle Bytes
Handle for idle watchers in the libuv event loop.
Idle watchers run their callbacks once per event loop iteration, right before
the event loop blocks for I/O. They are useful for performing background
tasks when the event loop is idle.
Example:
let uv = @uv.Loop::new()
let idle = @uv.Idle::new(uv)
idle.start(fn(_) {
println("Idle callback running")
idle.stop() catch {
error => println("Error stopping idle watcher: \{error}")
}
idle.close(_ => ())
})
uv.run(Default)
uv.close()
Idle) -> Unit
Unit raise type! Errno Status
Errno {
77 let Int
status = (idle : Idle) -> Int
uv_idle_stop(Idle
self)
78 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
79 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
80 }
81}
82