2012-04-27 106 views
0

我有以下錯誤: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

回答

1

您有幾種方式來解決您的問題。第一個是當您的預定功能啓動異常時顯式停止定時器。這給了這樣的事情:

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 

}