mirror of
https://github.com/vlang/v.git
synced 2025-09-15 15:32:27 +03:00
24 lines
453 B
V
24 lines
453 B
V
module util
|
|
|
|
import os
|
|
|
|
// TODO `select` doesn't work with time.Duration for some reason
|
|
pub fn execute_with_timeout(cmd string, timeout i64) ?os.Result {
|
|
ch := chan os.Result{cap: 1}
|
|
spawn fn [cmd] (c chan os.Result) {
|
|
res := os.execute(cmd)
|
|
c <- res
|
|
}(ch)
|
|
select {
|
|
a := <-ch {
|
|
return a
|
|
}
|
|
// timeout {
|
|
// 1000 * time.millisecond {
|
|
// timeout * time.millisecond {
|
|
timeout * 1_000_000 {
|
|
return none
|
|
}
|
|
}
|
|
return os.Result{}
|
|
}
|