stash/pkg/plugin/js/util.go

23 lines
370 B
Go
Raw Normal View History

2021-05-26 04:17:53 +00:00
package js
import (
"time"
"github.com/robertkrimen/otto"
)
func sleepFunc(call otto.FunctionCall) otto.Value {
arg := call.Argument(0)
ms, _ := arg.ToInteger()
time.Sleep(time.Millisecond * time.Duration(ms))
return otto.UndefinedValue()
}
func AddUtilAPI(vm *otto.Otto) {
util, _ := vm.Object("({})")
util.Set("Sleep", sleepFunc)
vm.Set("util", util)
}