Commit 6025ee41 authored by Romain Courteaud's avatar Romain Courteaud

Use new rsvp feature

parent 17f134ec
......@@ -45,23 +45,12 @@
try {
result = callback.apply(context, argument_list);
} catch (e) {
return new RSVP.Queue()
.push(function returnPushableError() {
return RSVP.reject(e);
});
return new RSVP.Queue(RSVP.reject(e));
}
if (result instanceof RSVP.Queue) {
return result;
}
return new RSVP.Queue()
.push(function returnPushableResult() {
return result;
}, function (e) {
if ((result !== undefined) && (result.cancel !== undefined)) {
result.cancel();
}
throw e;
});
return new RSVP.Queue(result);
}
function readBlobAsDataURL(blob) {
......@@ -116,20 +105,10 @@
try {
result = callback(evt);
} catch (e) {
result = RSVP.reject(e);
return reject(e);
}
callback_promise = result;
new RSVP.Queue()
.push(function waitForEventCallbackResult() {
return result;
})
.push(undefined, function handleEventCallbackError(error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
callback_promise = new RSVP.Queue(result).push(undefined, reject);
};
target.addEventListener(type, handle_event_callback, useCapture);
......@@ -428,16 +407,7 @@
if (resolved) {
throw new ResolvedMonitorError();
}
var queue = new RSVP.Queue()
.push(function waitForPromiseToMonitor() {
return promise_to_monitor;
}, function (e) {
if ((promise_to_monitor !== undefined) &&
(promise_to_monitor.cancel !== undefined)) {
promise_to_monitor.cancel();
}
throw e;
})
var queue = new RSVP.Queue(promise_to_monitor)
.push(function handlePromiseToMonitorSuccess(fulfillmentValue) {
// Promise to monitor is fullfilled, remove it from the list
var len = promise_list.length,
......@@ -453,13 +423,6 @@
}
promise_list = new_promise_list;
}, function handlePromiseToMonitorError(rejectedReason) {
if (rejectedReason instanceof RSVP.CancellationError) {
if (!(promise_to_monitor.isFulfilled &&
promise_to_monitor.isRejected)) {
// The queue could be cancelled before the first push is run
promise_to_monitor.cancel();
}
}
reject(rejectedReason);
throw rejectedReason;
});
......@@ -614,17 +577,16 @@
};
function runJob(gadget, name, callback, argument_list) {
var job_promise = ensurePushableQueue(callback, argument_list, gadget);
if (gadget.__job_dict.hasOwnProperty(name)) {
gadget.__job_dict[name].cancel();
}
var job_promise = ensurePushableQueue(callback, argument_list, gadget);
gadget.__job_dict[name] = job_promise;
// gadget.__monitor.monitor(job_promise
gadget.__monitor.monitor(new RSVP.Queue()
.push(function waitForJobPromise() {
return job_promise;
})
gadget.__monitor.monitor(new RSVP.Queue(job_promise)
.push(undefined, function handleJobError(error) {
// Do not crash monitor if the job has been cancelled
// by a new execution
if (!(error instanceof RSVP.CancellationError)) {
throw error;
}
......@@ -1212,15 +1174,7 @@
result = method(url, options, parent_gadget, old_element);
// Set the HTML context
if (typeof result.then === 'function') {
return new RSVP.Queue()
.push(function () {
return result;
}, function (e) {
if ((result !== undefined) && (result.cancel !== undefined)) {
result.cancel();
}
throw e;
})
return new RSVP.Queue(result)
.push(function setAsyncGadgetInstanceHTMLContext(gadget_instance) {
return setGadgetInstanceHTMLContext(gadget_instance, options,
parent_gadget, url,
......@@ -1940,11 +1894,8 @@
embedded_channel,
declare_method_list_waiting;
return new RSVP.Queue()
.push(function waitForLoadingGadget() {
// Wait for the loading gadget to be created
return wait_for_gadget_loaded;
})
// Wait for the loading gadget to be created
return new RSVP.Queue(wait_for_gadget_loaded)
.push(function handleLoadingGadget(result_list) {
TmpConstructor = result_list[0];
root_gadget = result_list[1];
......
......@@ -2578,21 +2578,13 @@
service_status.status = undefined;
klass.declareService(function () {
service_status.start_count += 1;
return new RSVP.Queue()
.push(function () {
service_status.status = "started";
return RSVP.defer().promise;
})
.push(undefined, function (error) {
service_status.stop_count += 1;
if (error instanceof RSVP.CancellationError) {
service_status.status = "stopped";
} else {
service_status.status = "error";
}
throw error;
});
return RSVP.Promise(function () {
service_status.start_count += 1;
service_status.status = "started";
}, function () {
service_status.stop_count += 1;
service_status.status = "stopped";
});
});
}
......@@ -3158,22 +3150,14 @@
service_status.stop_count = 0;
service_status.status = undefined;
klass.onEvent('bar', function (evt) {
service_status.start_count += 1;
return new RSVP.Queue()
.push(function () {
service_status.status = "started";
return RSVP.defer().promise;
})
.push(undefined, function (error) {
service_status.stop_count += 1;
if (error instanceof RSVP.CancellationError) {
service_status.status = "stopped";
} else {
service_status.status = "error";
}
throw error;
});
klass.onEvent('bar', function () {
return new RSVP.Promise(function () {
service_status.start_count += 1;
service_status.status = "started";
}, function () {
service_status.stop_count += 1;
service_status.status = "stopped";
});
});
}
......@@ -3430,22 +3414,14 @@
service_status.status = undefined;
klass.declareJob(name, function (parameter) {
service_status.start_count += 1;
service_status.parameter = parameter;
return new RSVP.Queue()
.push(function () {
service_status.status = "started";
return RSVP.defer().promise;
})
.push(undefined, function (error) {
service_status.stop_count += 1;
if (error instanceof RSVP.CancellationError) {
service_status.status = "stopped";
} else {
service_status.status = "error";
}
throw error;
});
return new RSVP.Promise(function () {
service_status.start_count += 1;
service_status.parameter = parameter;
service_status.status = "started";
}, function () {
service_status.stop_count += 1;
service_status.status = "stopped";
});
});
}
......
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