|
|
@ -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() |
|
|
|