Implement task sleep function
This commit is contained in:
parent
9b7dbcc141
commit
01f459ffaf
@ -8,7 +8,7 @@ homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[features]
|
||||
task = []
|
||||
task = ["tokio/time"]
|
||||
fs = ["tokio/fs"]
|
||||
net = ["tokio/net"]
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
-- include task functions in the global scope
|
||||
local task = require("lb:task")
|
||||
|
||||
-- include `lb_tasklib::spawn` in the global scope
|
||||
function sleep(ms)
|
||||
return task:sleep(ms)
|
||||
end
|
||||
|
||||
function spawn(f, ...)
|
||||
return task:spawn(f, ...)
|
||||
end
|
||||
|
@ -14,7 +14,11 @@ impl lb_tasklib {
|
||||
Self
|
||||
}
|
||||
|
||||
pub extern "Lua" fn spawn(self, f: function, ...) {
|
||||
pub async extern "Lua-C" fn sleep(&self, ms: f64) {
|
||||
sleep(Duration::from_secs_f64(ms / 1000.)).await;
|
||||
}
|
||||
|
||||
pub extern "Lua" fn spawn(&self, f: function, ...) {
|
||||
// pack the function and its arguments into a table and pass its ref to rust
|
||||
self.__spawn(__ref(__tpack(f, variadic!())))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user