From a3389de2d1ab9a3c7839118cd48365ac890516e2 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 18 May 2014 23:23:11 +0200 Subject: [PATCH 1/2] + deferred actually deferres --- headless_client.coffee | 13 +++++++++---- package.json | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/headless_client.coffee b/headless_client.coffee index ca91cc034..ea73e5956 100644 --- a/headless_client.coffee +++ b/headless_client.coffee @@ -1,6 +1,5 @@ ### This file will simulate games on node.js by emulating the browser environment. -At some point, most of the code can be merged with Simulator.coffee ### bowerComponentsPath = "./bower_components/" @@ -9,7 +8,7 @@ headlessClientPath = "./headless_client/" # SETTINGS options = workerCode: require headlessClientPath + 'worker_world' - debug: false # Enable logging of ajax calls mainly + debug: true # Enable logging of ajax calls mainly testing: false # Instead of simulating 'real' games, use the same one over and over again. Good for leak hunting. testFile: require headlessClientPath + 'test.js' leakTest: false # Install callback that tries to find leaks automatically @@ -27,7 +26,6 @@ disable = [ '../locale/locale' ] - # Start of the actual code. Setting up the enivronment to match the environment of the browser # the path used for the loader. __dirname is module dependent. @@ -108,6 +106,9 @@ $.ajax = (options) -> console.log "Requesting: " + JSON.stringify options if options.debug console.log "URL: " + url if options.debug + + deferred = Deferred() + request url: url jar: cookies @@ -124,15 +125,19 @@ $.ajax = (options) -> if (error) console.warn "\t↳Returned: error: #{error}" options.error(error) if options.error? + deferred.resolve() else console.log "\t↳Returned: statusCode #{response.statusCode}: #{if options.parse then JSON.stringify body else body}" if options.debug options.success(body, response, status: response.statusCode) if options.success? - + deferred.reject() statusCode = response.statusCode if response? options.complete(status: statusCode) if options.complete? responded = true + deferred.promise() + + $.extend = (deep, into, from) -> copy = _.clone(from, deep); if into diff --git a/package.json b/package.json index 59bfdb9e9..0725978ee 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "node-gyp": "~0.13.0", "aether": "~0.2.3", "JASON": "~0.1.3", - "JQDeferred": "^2.1.0" + "JQDeferred": "~2.1.0" }, "devDependencies": { "jade": "0.33.x", From 8a96bdd5dc61110e90dde72e89dff1a411d2ed39 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 18 May 2014 23:27:42 +0200 Subject: [PATCH 2/2] + Fixed headless_client --- headless_client.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/headless_client.coffee b/headless_client.coffee index ea73e5956..8fb9e49b5 100644 --- a/headless_client.coffee +++ b/headless_client.coffee @@ -8,7 +8,7 @@ headlessClientPath = "./headless_client/" # SETTINGS options = workerCode: require headlessClientPath + 'worker_world' - debug: true # Enable logging of ajax calls mainly + debug: false # Enable logging of ajax calls mainly testing: false # Instead of simulating 'real' games, use the same one over and over again. Good for leak hunting. testFile: require headlessClientPath + 'test.js' leakTest: false # Install callback that tries to find leaks automatically @@ -125,11 +125,12 @@ $.ajax = (options) -> if (error) console.warn "\t↳Returned: error: #{error}" options.error(error) if options.error? - deferred.resolve() + deferred.reject() + else console.log "\t↳Returned: statusCode #{response.statusCode}: #{if options.parse then JSON.stringify body else body}" if options.debug options.success(body, response, status: response.statusCode) if options.success? - deferred.reject() + deferred.resolve() statusCode = response.statusCode if response? options.complete(status: statusCode) if options.complete?