Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[refactor] runtime, ping: Just a quick refactor of the pull request #108

, no more set_connection_lost_handler but add_connection_lost_handler and move to PingClient
  • Loading branch information...
commit 4e4866115df6dccef6a8a555b274a7b01fa37bd7 1 parent 51e00c0
@BourgerieQuentin BourgerieQuentin authored
View
67 lib/plugins/server/session.js
@@ -1,5 +1,5 @@
/*
- Copyright © 2011, 2012 MLstate
+ Copyright © 2011-2013 MLstate
This file is part of Opa.
@@ -116,15 +116,21 @@ var LowLevelPingLoop = {};
// for setting a custom handler when the connection
// between client and server is lost.
- var connection_lost_handler = null;
+ var connection_lost_handlers = null;
+
+ function default_connection_lost_handler(){
+ jlog("Error: the connection with the server seems to be lost. Please reload");
+ }
function break_ping_loop() {
linked_with_server = false;
- if (connection_lost_handler == null) {
- jlog("Error: the connection with the server seems to be lost. Please reload");
- throw("Error: the connection with the server seems to be lost. Please reload");
+ if (connection_lost_handlers == null) {
+ default_connection_lost_handler();
} else {
- connection_lost_handler();
+ var i;
+ for(i in connection_lost_handlers){
+ connection_lost_handlers[i]();
+ }
}
}
@@ -477,13 +483,7 @@ var LowLevelPingLoop = {};
/** Make somethings when an error occurs with the ping loop */
function error_ping_response(xhr, str, exn){
if (failure_delay == max_failure_delay){
- if (connection_lost_handler == null) {
- jlog("Error: the connection with the server seems to be lost.");
- return;
- } else {
- connection_lost_handler();
- return;
- }
+ break_ping_loop();
} else {
//jlog("Warning: could not reach the server. Retrying in " + failure_delay);
}
@@ -580,14 +580,6 @@ var LowLevelPingLoop = {};
}
}
- LowLevelSession.set_domain_url = function(d) {
- domain_url = d;
- }
-
- LowLevelSession.set_connection_lost_handler = function(h) {
- connection_lost_handler = h;
- }
-
LowLevelSession.llmake = function(st, unserialize, fun_session,
ctx, dfun, more, concurrent) {
the_ping_loop();
@@ -722,6 +714,15 @@ var LowLevelPingLoop = {};
max_pang_attempt = i;
}
+ LowLevelPingLoop.set_domain_url = function(d) {
+ domain_url = d;
+ }
+
+ LowLevelPingLoop.add_connection_lost_handler = function(h) {
+ if(connection_lost_handlers == null) connection_lost_handlers = new Array();
+ connection_lost_handlers.push(h);
+ }
+
/**
* Make an internal synchronous request using the pang system. Can
* froze the client GUI. But the client can always interact with
@@ -772,22 +773,6 @@ function set_uu(x0, x1) {
}
/**
- * @register {(-> void) -> void}
- */
-function set_connection_lost_handler(f) {
- LowLevelSession.set_connection_lost_handler(f);
- return js_void;
-}
-
-/**
- * @register {string -> void}
- */
-function set_domain_url(d) {
- LowLevelSession.set_domain_url(d);
- return js_void;
-}
-
-/**
* @register {'st, \
(opa[option('ctx)], RPC.Json.private.native, \
continuation(opa[option('msg)]) -> void), \
@@ -1004,6 +989,14 @@ function get_server_id(chan, _) {
/** @register {string} internal_prefix LowLevelPingLoop.internal_prefix */
+ /**
+ * @register {(-> void) -> void} add_connection_lost_handler LowLevelPingLoop.add_connection_lost_handler
+ */
+
+ /**
+ * @register {string -> void} set_domain_url LowLevelPingLoop.set_domain_url
+ */
+
/** @endModule */
/* Hack for non cps client ****************************** */
View
23 lib/stdlib/core/rpc/core/ping_client.opa
@@ -1,5 +1,5 @@
/*
- Copyright © 2011, 2012 MLstate
+ Copyright © 2011-2013 MLstate
This file is part of Opa.
@@ -19,6 +19,7 @@ PingClient = {{
@private registers = Reference.create([]): reference(list(RPC.Json.json))
+ @package
register_actor(id) =
@atomic(
x = Reference.get(registers)
@@ -77,6 +78,26 @@ PingClient = {{
async_request(url, body) =
wrap_request(url, body, %%Session.PingRegister.ping_async_call%%)
+ /**
+ * Explicitely set the domain's URL used by AJAX request, no domain by default
+ */
+ set_domain_url =
+ %%Session.PingRegister.set_domain_url%%
+
+ /**
+ * Add a custom handler function for the case when the
+ * connection between client and server appears to be
+ * lost. If they are no custom handler, the default is to print
+ * "the connection with the server seems to be lost" to
+ * the client screen.
+ *
+ * Be sure to pass a `client` function here (e.g.
+ * `client function my_handler() { ... }`), as it will
+ * probably be called when the server is not available!
+ */
+ @client add_connection_lost_handler =
+ %%Session.PingRegister.add_connection_lost_handler%%
+
}}
@private
View
19 lib/stdlib/core/rpc/core/session.opa
@@ -185,25 +185,6 @@ type make_at_response = option(RPC.Json.json)
Session = {{
/**
- * Explicitely set the domain's URL used by AJAX request, no domain by default
- */
- @client set_domain_url = %%Session.set_domain_url%%
-
- /**
- * Set a custom handler function for the case when the
- * connection between client and server appears to be
- * lost. If this in not set, the default is to print
- * "the connection with the server seems to be lost" to
- * the client screen.
- *
- * Be sure to pass a `client` function here (e.g.
- * `client function my_handler() { ... }`), as it will
- * probably be called when the server is not available!
- */
- @client set_connection_lost_handler =
- %%Session.set_connection_lost_handler%%
-
- /**
* {2 Creating sessions}
*/
Please sign in to comment.
Something went wrong with that request. Please try again.