Add sleep method.
@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"path"
+ "time"
)
var (
@@ -347,6 +348,17 @@ var builtinGlobalMethods = []*BuiltInMethodObject{
}
},
},
+ {
+ Name: "sleep",
+ Fn: func(receiver Object) builtinMethodBody {
+ return func(t *thread, args []Object, blockFrame *callFrame) Object {
+ int := args[0].(*IntegerObject)
+ seconds := int.Value
+ time.Sleep(time.Duration(seconds) * time.Second)
+ return int
+ }
+ },
+ },
}
// BuiltinClassMethods is a collection of class methods used by Class
