0

I have the following error :

Error: uncaught OPA exception {OpaRPC_Server: {timeout: {client: {client: $"j98soqx7hbavgq2scg915j7mlkctdeop"$; page: $1
042254815$}; fun_id: $"_v0_get_value_stdlib.core.xhtml"$}}}

with the simple code below :

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"
  }
)

The error appears when I close the tab running the application. It seems that the timer continues to work event though the tab has been close.

How can I stop it ?

Thanks,

kayhman

Guillaume
  • 289
  • 1
  • 7

1 Answers1

1

You have several way to fix your issue. The first one is to explicitly stop the timer when an exception is launched by your scheduled function. That give somethings like that :

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
}

But the issue comes because your timer is executed on the server side (because it is created by the start function).

Thus the better fix it's to set your timer on the client side. You have several way to do this.

1 - Just tag your timer @client, it will be executed on the client toplevel. But it's a bit "violent". Because it will be launched on all pages.

@client x = Scheduler.timer(3000, function() {#copy =+ Dom.get_value(#text)})

2 - Start in an onready event, the timer will start when the div #copy is ready.

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

}