You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.2 KiB

package jsruntime
import (
"github.com/dop251/goja"
)
func (jr *JsRuntime) EnableTimeoutFunc() {
//
//var funs []func()
//var task func()
//task = func() {
// recover()
// go task()
// for ; ; {
// l := len(funs)
// if len(funs) > 0 {
// fun := funs[l-1]
// funs = funs[:l-1]
// fun()
// }
// time.Sleep(time.Second / 100)
// }
//}
//go task()
jr.runtime.Set("setTimeout", func(call goja.FunctionCall) goja.Value {
//log.Println("setTimeout")
//log.Println(call.Argument(0))
if fn, ok := goja.AssertFunction(call.Argument(0)); ok {
//delay := call.Argument(1).ToInteger()
var args []goja.Value
if len(call.Arguments) > 2 {
args = call.Arguments[2:]
}
//time.Sleep(time.Duration(delay) * time.Millisecond)
fn(nil, args...)
//
//time.AfterFunc(time.Duration(delay) * time.Millisecond, func(){
// fn(nil, args...)
//})
//funs = append(funs, func() {
// time.Sleep(time.Duration(delay) * time.Millisecond)
// fn(nil, args...)
//})
//log.Println("setTimeout ok")
}
return jr.runtime.ToValue(123124512)
})
jr.runtime.Set("clearTimeout", func(i int64) {
//log.Println("clearTimeout")
})
}