OPA服务器超时
问题描述:
我有以下错误:OPA服务器超时
Error: uncaught OPA exception {OpaRPC_Server: {timeout: {client: {client: $"j98soqx7hbavgq2scg915j7mlkctdeop"$; page: $1
042254815$}; fun_id: $"_v0_get_value_stdlib.core.xhtml"$}}}
与下面的简单代码:
function start()
{
content = <textarea style="width:30%;" rows=1 id=#text > text </textarea> <+>
<div id=#copy></div>
Scheduler.timer(3000, function() {#copy =+ Dom.get_value(#text)})
content
}
Server.start(
Server.http,
{ page:start,
title:"bug timer"
}
)
出现错误,当我关闭所有正在运行的应用程序的选项卡。看起来,定时器继续工作事件,虽然选项卡已关闭。
我该如何阻止它?
感谢,
kayhman
答
您有几种方式来解决您的问题。第一个是当您的预定功能启动异常时显式停止定时器。这给了这样的事情:
function start()
{
content = <textarea style="width:30%;" rows=1 id=#text > text </textarea> <+>
<div id=#copy></div>
recursive timer =
Scheduler.make_timer(3000, function() {
@catch(function(exn){Log.error("EXN", "{exn}"); timer.stop()},
#copy =+ Dom.get_value(#text))
}
)
content
}
但问题来了,因为你的计时器是在服务器端执行(因为它是由启动函数创建)。
因此,更好的解决方法是在客户端设置您的计时器。你有几种方法来做到这一点。
1 - 只需标记您的计时器@client,它将在客户端顶层执行。但它有点“暴力”。因为它将在所有页面上启动。
@client x = Scheduler.timer(3000, function() {#copy =+ Dom.get_value(#text)})
2 - 从onready事件开始,计时器将在div #copy准备就绪时启动。
function start()
{
content = <textarea style="width:30%;" rows=1 id=#text > text </textarea> <+>
<div id=#copy onready={function(_){
Scheduler.timer(3000, function() {#copy =+ Dom.get_value(#text)})
}}
></div>
Scheduler.timer(3000, function() {#copy =+ Dom.get_value(#text)})
content
}