本文整理匯總了Golang中github.com/robertkrimen/otto.Otto.Interrupt方法的典型用法代碼示例。如果您正苦於以下問題:Golang Otto.Interrupt方法的具體用法?Golang Otto.Interrupt怎麽用?Golang Otto.Interrupt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robertkrimen/otto.Otto
的用法示例。
在下文中一共展示了Otto.Interrupt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runUnsafeJavascript
func runUnsafeJavascript(vm *otto.Otto, unsafe string) (otto.Value, error) {
start := time.Now()
defer func() {
duration := time.Since(start)
if err := recover(); err != nil {
if err == halt {
fmt.Println("Some code took too long! Stopping after: ", duration)
}
panic(err)
}
}()
vm.Interrupt = make(chan func(), 1)
go func() {
time.Sleep(maxExecutionTime * time.Second)
vm.Interrupt <- func() {
panic(halt)
}
}()
return vm.Run(unsafe)
}