ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject incubator-ignite git commit: #ignite-961-promises: remove debug.
Date Mon, 13 Jul 2015 13:59:33 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-961-promise 5562484a3 -> e97945747


#ignite-961-promises: remove debug.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e9794574
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e9794574
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e9794574

Branch: refs/heads/ignite-961-promise
Commit: e979457478e974c6a0a4d632f003bacd10c86213
Parents: 5562484
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jul 13 16:59:29 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jul 13 16:59:29 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/main/js/cache-promise.js | 88 ++++++++++--------------
 1 file changed, 38 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e9794574/modules/nodejs/src/main/js/cache-promise.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache-promise.js b/modules/nodejs/src/main/js/cache-promise.js
index 1c0b489..8c4d329 100644
--- a/modules/nodejs/src/main/js/cache-promise.js
+++ b/modules/nodejs/src/main/js/cache-promise.js
@@ -71,21 +71,18 @@ CachePromise.prototype.query = function(qry) {
     var command = this._createQueryCommand("qryexecute", qry).addParam("type", qry.returnType()).
         setPostData(JSON.stringify({"arg" : qry.arguments()}));
 
-    function onResult(resolve, reject, err, res) {
-        if(err != null) {
-            reject(err);
-        }
-        else {
-            console.log("res:" + JSON.stringify(res));
-            resolve(new Cursor(qry, res));
-        }
-    }
-
-    function makePromise(server, resolve, reject) {
-        server.runCommand(command, onResult.bind(null, resolve, reject));
-    }
-
-    return new Promise(makePromise.bind(null, this._server));
+    var server = this._server;
+
+    return new Promise(function(resolve, reject) {
+        server.runCommand(command, function(err, res){
+            if(err != null) {
+                reject(err);
+            }
+            else {
+                resolve(new Cursor(qry, res));
+            }
+        });
+    });
 }
 
 Cursor = function(qry, res) {
@@ -95,29 +92,24 @@ Cursor = function(qry, res) {
 
 Cursor.prototype.next = function() {
     if (this._res["last"]) {
-        throw "Do not have more pages";
-    }
-
-    var command = this._createCommand("qryfetch");
-
-    command.addParam("qryId", _res.queryId).addParam("psz", _qry.pageSize());
-
-    function onResult(resolve, reject, err, res) {
-        if(err != null) {
-            reject(err);
-        }
-        else {
-            resolve(new Cursor(qry, res));
-        }
+        throw "All pages are returned.";
     }
 
-    function makePromise(server, resolve, reject) {
-        server.runCommand(command, onResult.bind(null, resolve, reject));
-    }
-
-    this._server.runCommand(command, onQueryExecute.bind(this, _qry));
-
-    return new Promise(makePromise);
+    var cmd = this._createCommand("qryfetch").addParam("qryId", _res.queryId).
+        addParam("psz", _qry.pageSize());
+
+    var server = this._server;
+
+    return new Promise(function(resolve, reject) {
+       server.runCommand(cmd, function(err, res) {
+           if(err != null) {
+               reject(err);
+           }
+           else {
+               resolve(new Cursor(qry, res));
+           }
+       });
+    });
 }
 
 Cursor.prototype.page = function() {
@@ -129,20 +121,16 @@ Cursor.prototype.isFinished = function() {
 }
 
 CachePromise.prototype.__createPromise = function(cmd) {
-    function onResult(resolve, reject, err, res) {
-        if(err != null) {
-            reject(err);
-        }
-        else {
-            resolve(res);
-        }
-    }
-
-    function makePromise(server, resolve, reject) {
-        server.runCommand(cmd, onResult.bind(null, resolve, reject));
-    }
-
-    return new Promise(makePromise.bind(null, this._server));
+    return new Promise(function(resolve, reject) {
+        server.runCommand(cmd, function(err, res) {
+            if(err != null) {
+                reject(err);
+            }
+            else {
+                resolve(res);
+            }
+        });
+    });
 }
 
 


Mime
View raw message