diff --git a/jsruntime/runtime.go b/jsruntime/runtime.go
index de9e22f..c6f0529 100644
--- a/jsruntime/runtime.go
+++ b/jsruntime/runtime.go
@@ -26,6 +26,7 @@ type JsRuntime struct {
mutex sync.Mutex
RenderCallBackFun func(string)
IsDebugModel bool
+ isRenderIng bool
}
type Rely struct {
@@ -217,6 +218,7 @@ func (jr *JsRuntime) RunCode(code string) error {
}
func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}, cb func(data string)) (err error) {
+
jr.RenderCallBackFun = cb
jr.mutex.Lock()
defer jr.mutex.Unlock()
@@ -224,9 +226,11 @@ func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}
runtime := jr.runtime
mainSrc := jr.MainSrc
isLock := true
+ jr.isRenderIng = true
//timeoutSec := jr.TimeoutSec
defer func() {
+ jr.isRenderIng = false
isLock = false
jr.runtime.ClearInterrupt()
}()
@@ -266,9 +270,11 @@ func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}
jr.RenderCallBackFun(data)
})
- t := time.AfterFunc(time.Duration(jr.TimeoutSec), func() {
- jr.runtime.Interrupt("time out")
- jr.runtime.ClearInterrupt()
+ t := time.AfterFunc(time.Duration(jr.TimeoutSec)*time.Second, func() {
+ if jr.isRenderIng {
+ jr.runtime.Interrupt("time out")
+ jr.runtime.ClearInterrupt()
+ }
})
defer t.Stop()
diff --git a/jsruntime/timeout.go b/jsruntime/timeout.go
index 60423a8..6bb0241 100644
--- a/jsruntime/timeout.go
+++ b/jsruntime/timeout.go
@@ -3,6 +3,7 @@ package jsruntime
import (
"github.com/dop251/goja"
"log"
+ "time"
)
func (jr *JsRuntime) EnableTimeoutFunc() {
@@ -10,13 +11,13 @@ func (jr *JsRuntime) EnableTimeoutFunc() {
jr.runtime.Set("setTimeout", func(call goja.FunctionCall) goja.Value {
if fn, ok := goja.AssertFunction(call.Argument(0)); ok {
- //delay := call.Argument(1).ToInteger()
+ 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)
+ time.Sleep(time.Duration(delay) * time.Millisecond)
fn(nil, args...)
}
diff --git a/static/index.html b/static/index.html
index 4df7112..02e5f58 100644
--- a/static/index.html
+++ b/static/index.html
@@ -13,7 +13,7 @@
- {{desc}}
+ {{desc}}