X-Git-Url: http://nitlanguage.org diff --git a/lib/app/http_request.nit b/lib/app/http_request.nit index 70990a9..694ba33 100644 --- a/lib/app/http_request.nit +++ b/lib/app/http_request.nit @@ -21,20 +21,28 @@ import json::serialization import linux::http_request is conditional(linux) import android::http_request is conditional(android) +import ios::http_request is conditional(ios) redef class App # Platform specific service to execute `task` on the main/UI thread fun run_on_ui_thread(task: Task) is abstract end -# Thread executing an HTTP request and deserializing JSON asynchronously +# Thread executing an HTTP request asynchronously # -# This class defines four methods acting on the main/UI thread, -# they should be implemented as needed: -# * before -# * on_load -# * on_fail -# * after +# The request is sent to `rest_server_uri / rest_action`. +# +# If `deserialize_json`, the default behavior, the response is deserialized from JSON +# +# If `delay > 0.0`, sending the reqest is delayed by the given `delay` in seconds. +# It can be used to delay resending a request on error. +# +# Four callback methods act on the main/UI thread, +# they should be implemented as needed in subclasses: +# * `before` +# * `on_load` +# * `on_fail` +# * `after` class AsyncHttpRequest super Thread @@ -47,6 +55,9 @@ class AsyncHttpRequest # Should the response content be deserialized from JSON? var deserialize_json = true is writable + # Delay in seconds before sending this request + var delay = 0.0 is writable + redef fun start do before @@ -55,6 +66,9 @@ class AsyncHttpRequest redef fun main do + var delay = delay + if delay > 0.0 then delay.sleep + var uri = rest_server_uri / rest_action # Execute REST request