Commit 4fe2c534 authored by Tristan Cavelier's avatar Tristan Cavelier

jio dashboard function made promise based

parent 13c35ce3
...@@ -272,19 +272,24 @@ function printLocalStorage() { ...@@ -272,19 +272,24 @@ function printLocalStorage() {
log("localStorage content\n" + JSON.stringify(localStorage, null, " ")); log("localStorage content\n" + JSON.stringify(localStorage, null, " "));
} }
function callback(err, val, begin_date) { function logError(begin_date, err) {
log('time : ' + (Date.now() - begin_date));
error('return :' + JSON.stringify(err, null, " "));
throw err;
}
function logAnswer(begin_date, val) {
log('time : ' + (Date.now() - begin_date)); log('time : ' + (Date.now() - begin_date));
if (err) {
return error('return :' + JSON.stringify(err, null, " "));
}
log('return : ' + JSON.stringify(val, null, " ")); log('return : ' + JSON.stringify(val, null, " "));
return val;
} }
function command(method, num) { function command(method, num) {
var begin_date = Date.now(), doc = {}, opts = {}; var begin_date = Date.now(), doc = {}, opts = {};
if (!my_jio) { if (!my_jio) {
return error('no jio set'); error('no jio set');
return;
} }
doc = select('#metadata').value; doc = select('#metadata').value;
...@@ -302,22 +307,20 @@ function command(method, num) { ...@@ -302,22 +307,20 @@ function command(method, num) {
'\nopts: ' + JSON.stringify(opts, null, " ")); '\nopts: ' + JSON.stringify(opts, null, " "));
if (method === "allDocs") { if (method === "allDocs") {
my_jio.allDocs(opts).then(function (answer) { return my_jio.allDocs(opts).then(
callback(undefined, answer, begin_date); logAnswer.bind(null, begin_date),
}, function (error) { logError.bind(null, begin_date)
callback(error, undefined, begin_date); );
});
} else { } else {
my_jio[method](doc, opts).then(function (answer) { return my_jio[method](doc, opts).then(
callback(undefined, answer, begin_date); logAnswer.bind(null, begin_date),
}, function (error) { logError.bind(null, begin_date)
callback(error, undefined, begin_date); );
});
} }
} }
function doCommandNTimes(method) { function doCommandNTimes(method) {
var i = -1, n = 0, lock; var i = -1, n = 0, lock, promise_list = [];
n = parseInt(select("#times").value, 10); n = parseInt(select("#times").value, 10);
lock = select("#times-lock").checked; lock = select("#times-lock").checked;
if (!lock) { if (!lock) {
...@@ -327,39 +330,40 @@ function doCommandNTimes(method) { ...@@ -327,39 +330,40 @@ function doCommandNTimes(method) {
n = 1; n = 1;
} }
while (++i < n) { while (++i < n) {
command(method, i); promise_list.push(command(method, i));
} }
return RSVP.all(promise_list);
} }
function post() { function post() {
doCommandNTimes("post"); return doCommandNTimes("post");
} }
function put() { function put() {
doCommandNTimes("put"); return doCommandNTimes("put");
} }
function get() { function get() {
doCommandNTimes("get"); return doCommandNTimes("get");
} }
function remove() { function remove() {
doCommandNTimes("remove"); return doCommandNTimes("remove");
} }
function putAttachment() { function putAttachment() {
doCommandNTimes("putAttachment"); return doCommandNTimes("putAttachment");
} }
function getAttachment() { function getAttachment() {
doCommandNTimes("getAttachment"); return doCommandNTimes("getAttachment");
} }
function removeAttachment() { function removeAttachment() {
doCommandNTimes("removeAttachment"); return doCommandNTimes("removeAttachment");
} }
function allDocs() { function allDocs() {
doCommandNTimes("allDocs"); return doCommandNTimes("allDocs");
} }
function check() { function check() {
doCommandNTimes("check"); return doCommandNTimes("check");
} }
function repair() { function repair() {
doCommandNTimes("repair"); return doCommandNTimes("repair");
} }
//--> //-->
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment