# HG changeset patch # User Andreas Tolfsen # Date 1519645472 0 # Node ID 00b77f68b9fb96f239aef03c810bdfc8cf4c3beb # Parent ffbc1e20455e9b11487970929c9adfbc70325218 Bug 1441019 - Migrate sync module docs to RST. r=whimboo MozReview-Commit-ID: 7MW7SNlFWjz diff --git a/testing/marionette/sync.js b/testing/marionette/sync.js --- a/testing/marionette/sync.js +++ b/testing/marionette/sync.js @@ -20,70 +20,65 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLA * @param {function(*)} resolve * To be called when the condition has been met. Will return the * resolved value. * @param {function} reject * To be called when the condition has not been met. Will cause * the condition to be revaluated or time out. * * @return {*} - * The value from calling resolve. + * The value from calling ``resolve``. */ /** - * Runs a promise-like function off the main thread until it is resolved - * through resolve or rejected callbacks. - * The function is guaranteed to be run at least once, irregardless of - * the timeout. + * Runs a Promise-like function off the main thread until it is resolved + * through ``resolve`` or ``rejected`` callbacks. The function is + * guaranteed to be run at least once, irregardless of the timeout. * - * The func is evaluated every interval for as - * long as its runtime duration does not exceed interval. - * Evaluations occur sequentially, meaning that evaluations of - * func are queued if the runtime evaluation duration of - * func is greater than interval. + * The ``func`` is evaluated every ``interval`` for as long as its + * runtime duration does not exceed ``interval``. Evaluations occur + * sequentially, meaning that evaluations of ``func`` are queued if + * the runtime evaluation duration of ``func`` is greater than ``interval``. * - * func is given two arguments, resolve and - * reject, of which one must be called for the evaluation - * to complete. Calling resolve with an argument - * indicates that the expected wait condition was met and will return - * the passed value to the caller. Conversely, calling - * reject will evaluate func again until - * the timeout duration has elapsed or func - * throws. The passed value to reject will also be - * returned to the caller once the wait has expired. + * ``func`` is given two arguments, ``resolve`` and ``reject``, + * of which one must be called for the evaluation to complete. + * Calling ``resolve`` with an argument indicates that the expected + * wait condition was met and will return the passed value to the + * caller. Conversely, calling ``reject`` will evaluate ``func`` + * again until the ``timeout`` duration has elapsed or ``func`` throws. + * The passed value to ``reject`` will also be returned to the caller + * once the wait has expired. * - * Usage: + * Usage:: * - *

  *     let els = new PollPromise((resolve, reject) => {
  *       let res = document.querySelectorAll("p");
  *       if (res.length > 0) {
  *         resolve(Array.from(res));
  *       } else {
  *         reject([]);
  *       }
  *     });
- * 
* * @param {Condition} func * Function to run off the main thread. * @param {number=} [timeout=2000] timeout * Desired timeout. If 0 or less than the runtime evaluation - * time of func, func is guaranteed to run - * at least once. The default is 2000 milliseconds. + * time of ``func``, ``func`` is guaranteed to run at least once. + * The default is 2000 milliseconds. * @param {number=} [interval=10] interval - * Duration between each poll of func in milliseconds. + * Duration between each poll of ``func`` in milliseconds. * Defaults to 10 milliseconds. * * @return {Promise.<*>} - * Yields the value passed to func's - * resolve or reject callbacks. + * Yields the value passed to ``func``'s + * ``resolve`` or ``reject`` callbacks. * * @throws {*} - * If func throws, its error is propagated. + * If ``func`` throws, its error is propagated. */ function PollPromise(func, {timeout = 2000, interval = 10} = {}) { const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); return new Promise((resolve, reject) => { const start = new Date().getTime(); const end = start + timeout; @@ -112,33 +107,31 @@ function PollPromise(func, {timeout = 20 return res; }, err => { timer.cancel(); throw err; }); } /** - * The TimedPromise object represents the timed, eventual - * completion (or failure) of an asynchronous operation, and its - * resulting value. + * Represents the timed, eventual completion (or failure) of an + * asynchronous operation, and its resulting value. * - * In contrast to a regular {@link Promise}, it times out after - * timeout. + * In contrast to a regular Promise, it times out after ``timeout``. * * @param {Condition} func - * Function to run, which will have its reject - * callback invoked after the timeout duration is reached. - * It is given two callbacks: resolve(value) and - * reject(error). + * Function to run, which will have its ``reject`` + * callback invoked after the ``timeout`` duration is reached. + * It is given two callbacks: ``resolve(value)`` and + * ``reject(error)``. * @param {timeout=} [timeout=1500] timeout - * condition's reject callback will be called + * ``condition``'s ``reject`` callback will be called * after this timeout. * @param {Error=} [throws=TimeoutError] throws - * When the timeout is hit, this error class will be + * When the ``timeout`` is hit, this error class will be * thrown. If it is null, no error is thrown and the promise is * instead resolved on timeout. * * @return {Promise.<*>} * Timed promise. */ function TimedPromise(fn, {timeout = 1500, throws = TimeoutError} = {}) { const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);