MLstate/opalang — pull request #108 by ogunden (2013-02-28 23:14:37+00:00)
Title: [feature] add Session.set_connection_lost_handler

Added a way to set a custom callback function to be called
when the client detects that it has been disconnected
from the server.

Prior to this patch, the behavior was always to print to
the jlog (browser page): "The connexion to the server seems
to have been lost." Now the programmer can customize this
behavior.

Here is a fully-functional and tested usage case:

import stdlib.core.rpc.core;
import stdlib.web.client;

client function my_connection_lost_handler() {
Client.alert("connection lost, press OK to reload");
Client.reload();
}

function setup_handler() {
Session.set_connection_lost_handler(my_connection_lost_handler);
}

function page() {

this is the custom connection handler
test page. try killing the server and
waiting a couple of minutes.

}

Server.start(Server.http,
{title:"connection handler test", page:page})

Caveats: like many functions in Opa, if you call
set_connection_lost_handler before the client has finished
loading the page, your app will hang. To avoid this, always
call it from within an `onready` or another type of event
handler.