aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/sloth_std/time.rs
blob: 4df715edc4baf42059eded97862175720aab943f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::{thread, time};

use crate::native::{self, NativeFunction, NativeFunctionResult};
use crate::value::Primitive;
use crate::value::Primitive::Integer;
use crate::VM;

fn wait(_vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
    let sec = args.get(0).cloned();

    let Some(Integer(sec)) = sec else {
        return Err(native::Error::InvalidArgument);
    };

    thread::sleep(time::Duration::from_secs(sec.try_into().unwrap()));

    Ok(Primitive::Empty)
}

pub const WAIT: NativeFunction = NativeFunction {
    name: "wait",
    function: wait,
    arity: 1,
    returns_value: false,
};