From e3cedc8e9e8c28a998634c71ad71613292317208 Mon Sep 17 00:00:00 2001 From: Tristan Cavelier <tristan.cavelier@nexedi.com> Date: Fri, 3 Jun 2016 15:33:50 +0200 Subject: [PATCH] erp5_web_renderjs_ui: add promiseDoWhile tool to rjs_gadget_global_js.js /reviewed-on https://lab.nexedi.com/nexedi/erp5/merge_requests/122 --- .../web_page_module/rjs_gadget_global_js.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_global_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_global_js.js index 812a20aea1..a3370c42f3 100644 --- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_global_js.js +++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_global_js.js @@ -101,4 +101,29 @@ }); }; + window.promiseDoWhile = function (loopFunction, input) { + // calls loopFunction(input) until it returns a non positive value + + // this queue is to protect the inner loop queue from the + // `promiseDoWhile` caller, avoiding it to enqueue the inner + // loop queue. + return new RSVP.Queue() + .push(function () { + // here is the inner loop queue + var loop_queue = new RSVP.Queue(); + function iterate(previous_iteration_result) { + if (!previous_iteration_result) { + return input; + } + loop_queue.push(iterate); + return loopFunction(input); + } + return loop_queue + .push(function () { + return loopFunction(input); + }) + .push(iterate); + }); + }; + }(window, RSVP, FileReader)); \ No newline at end of file -- 2.30.9