defer.js 730 B

1234567891011121314151617181920212223242526
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. // See bug 1273941 to understand this choice of promise.
  6. const Promise = require("promise");
  7. /**
  8. * Returns a deferred object, with a resolve and reject property.
  9. * https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Deferred
  10. */
  11. module.exports = function defer() {
  12. let resolve, reject;
  13. let promise = new Promise(function () {
  14. resolve = arguments[0];
  15. reject = arguments[1];
  16. });
  17. return {
  18. resolve: resolve,
  19. reject: reject,
  20. promise: promise
  21. };
  22. };