Public Vars

Back

js-async (clj)

(source)

multimethod

(js-async driver script & args)
Return result of `driver` executing JavaScript `script` with `args` asynchornously in the browser. Executes an asynchronous script in the browser and returns the result. An asynchronous script one that typically performs some kind of IO operation, like an AJAX request to the server. You cannot just use the `return` statement like you do in synchronous scripts. The driver passes a special handler as the last argument that should be called to return the final result. *Note:* calling this function requires the `script` timeout to be set properly, meaning non-zero positive value. See [[get-script-timeout]], [[set-script-timeout]] and [[with-script-timeout]]. - `args`: additional arguments for your code. Automatically converted to JSON. Example of a script: ```Clojure // the `arguments` would be an array of something like: // [1, 2, true, ..., <special callback added by driver>] var callback = arguments[arguments.length-1]; // so the main script would look like: $.ajax({url: '/some/url', success: function(result) { if (isResultOk(result)) { callback({ok: getProgressData(result)}); } else { callback({error: getErrorData(result)}); } }}); ```

Examples