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AU,SAAU,EAAM,GAC9C,IAAI,EAAW,YAAY,GAAQ,IAC/B,EAAW,QAGf,OAFA,EAAS,KAAK,EAAS,oBACvB,KAAK,KAAK,EAAM,GAAU,KAAK,EAAS,QACjC,EAAS,OAClB,IAYA,UAAU,CAAC,QAAS,SAAU,YAAY,SAAU,GAGlD,IAAI,EAAW,YAAY,UAAW,GAClC,EAAW,QAGf,OAFA,EAAS,KAAK,EAAS,oBACvB,KAAK,KAAK,EAAM,GAAU,KAAK,EAAS,QACjC,EAAS,OAClB,IAYA,UAAU,WAAW,SAAU,GAC7B,IAAI,EAOF,OAAO,KANP,KAAK,MAAK,SAAU,GAClB,EAAS,KAAM,EACjB,IAAG,SAAU,GACX,EAAS,EACX,GAIJ,IAEA,EAAE,WAAa,WACb,MAAM,IAAI,MAAM,qDAClB","file":"/npm/q-vanilla@3.0.0/lib/q.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/q-vanilla@3.0.0/lib/q.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\nexports[\"default\"] = exports.Q = Q;\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n// vim:ts=4:sts=4:sw=4:\n\n/*!\n *\n * Copyright 2009-2017 Kris Kowal under the terms of the MIT\n * license found at https://github.com/kriskowal/q/blob/v1/LICENSE\n *\n * With parts by Tyler Close\n * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found\n * at http://www.opensource.org/licenses/mit-license.html\n * Forked at ref_send.js version: 2009-05-11\n *\n * With parts by Mark Miller\n * Copyright (C) 2011 Google Inc.\n *\n * With changes by Stephan Hohe\n * Copyright 2018 Stephan Hohe\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n// shims\n// used for fallback in \"allResolved\"\nvar noop = function noop() {};\n\nfunction notImplementedError(name) {\n  return new Error(\"Q: function\" + (name ? \" \" + name : \"\") + \" not implemented\");\n}\n\nfunction notImplemented(obj, name) {\n  obj[name] = function () {\n    throw notImplementedError(name);\n  };\n}\n\nfunction QP_export(names, fun) {\n  function setf(name) {\n    QPromise.prototype[name] = fun;\n\n    Q[name] = function (object) {\n      var p = Q(object);\n      return p[name].apply(p, array_slice(arguments, 1));\n    };\n  }\n\n  if (typeof names === \"string\") {\n    setf(names);\n  } else {\n    names.forEach(setf);\n  }\n} // Attempt to make generics safe in the face of downstream\n// modifications.\n// There is no situation where this is necessary.\n// If you need a security guarantee, these primordials need to be\n// deeply frozen anyway, and if you don’t need a security guarantee,\n// this is just plain paranoid.\n// However, this **might** have the nice side-effect of reducing the size of\n// the minified code by reducing x.call() to merely x()\n// See Mark Miller’s explanation of what this does.\n// http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming\n\n\nvar call = Function.call;\n\nfunction uncurryThis(f) {\n  return function () {\n    return call.apply(f, arguments);\n  };\n} // This is equivalent, but slower:\n// uncurryThis = Function_bind.bind(Function_bind.call);\n// http://jsperf.com/uncurrythis\n\n\nvar array_slice = uncurryThis(Array.prototype.slice);\nvar array_reduce = uncurryThis(Array.prototype.reduce);\nvar array_map = uncurryThis(Array.prototype.map);\n\nfunction isObject(value) {\n  return value === Object(value);\n} // generator related shims\n// FIXME: Remove this function once ES6 generators are in SpiderMonkey.\n\n\nfunction isStopIteration(exception) {\n  return Object.prototype.toString.call(exception) === \"[object StopIteration]\" || exception instanceof QReturnValue;\n} // FIXME: Remove this helper and Q.return once ES6 generators are in\n// SpiderMonkey.\n\n\nvar QReturnValue;\n\nif (typeof ReturnValue !== \"undefined\") {\n  QReturnValue = ReturnValue;\n} else {\n  QReturnValue = function QReturnValue(value) {\n    this.value = value;\n  };\n} // end of shims\n// beginning of real work\n\n\nvar QPromise = /*#__PURE__*/_createClass(function QPromise(nativePromise, inspect) {\n  _classCallCheck(this, QPromise);\n\n  if (inspect === void 0) {\n    inspect = {\n      state: \"unknown\"\n    };\n  }\n\n  this._native = nativePromise.then();\n  this._inspect = inspect;\n  var that = this;\n  nativePromise.then(function (value) {\n    that._inspect.state = \"fulfilled\";\n    that._inspect.value = value;\n  }, function (reason) {\n    that._inspect.state = \"rejected\";\n    that._inspect.reason = reason;\n  }); // If trackUnhandledRejections is false, we always add an error handler\n  // to the native promise to avoid the host system to complain about\n  // unhandled rejections.\n  //\n  // If trackUnhandledRejections is true we don't do this and let the\n  // host system keep track of unhandled exceptions.\n\n  if (!trackUnhandledRejections) {\n    this._native.then(void 0, function () {});\n  }\n});\n/**\n * Constructs a promise for an immediate reference, passes promises through, or\n * coerces promises from different systems.\n * @param value immediate reference or promise\n */\n\n\nfunction Q(value) {\n  // If the object is already a Promise, return it directly.  This enables\n  // the resolve function to both be used to created references from objects,\n  // but to tolerably coerce non-promises to promises.\n  if (value instanceof QPromise) {\n    return value;\n  }\n\n  if (value instanceof Promise) {\n    return new QPromise(value, {\n      state: \"pending\"\n    });\n  } // assimilate thenables\n\n\n  if (isPromiseAlike(value)) {\n    return coerce(value);\n  } else {\n    return Q.fulfill(value);\n  }\n}\n\nQ.resolve = Q;\n/**\n * Performs a task in a future turn of the event loop.\n * @param {Function} task\n */\n\nnotImplemented(Q, \"nextTick\");\n\nvar Deferred = /*#__PURE__*/function () {\n  function Deferred() {\n    _classCallCheck(this, Deferred);\n\n    var that = this;\n    var native_promise = new Promise(function (resolve, reject) {\n      that.native_resolve = resolve;\n      that.native_reject = reject;\n    });\n    var promise = new QPromise(native_promise, {\n      state: \"pending\"\n    });\n    this.promise = promise;\n    this.resolve = this.resolve.bind(this);\n    this.fulfill = this.fulfill.bind(this);\n    this.reject = this.reject.bind(this);\n  }\n\n  _createClass(Deferred, [{\n    key: \"resolve\",\n    value: function resolve(value) {\n      if (value instanceof QPromise) {\n        if (this.promise._inspect.state !== \"fulfilled\" && this.promise._inspect.state !== \"rejected\") {\n          if (value._inspect.state === \"fulfilled\") {\n            this.promise._inspect.state = \"fulfilled\";\n            this.promise._inspect.value = value._inspect.value;\n          } else if (value._inspect.state === \"rejected\") {\n            this.promise._inspect.state = \"rejected\";\n            this.promise._inspect.reason = value._inspect.reason;\n          }\n        }\n\n        this.native_resolve(value._native);\n      } else {\n        if (!isPromiseAlike(value)) {\n          if (this.promise._inspect.state !== \"fulfilled\" && this.promise._inspect.state !== \"rejected\") {\n            this.promise._inspect.state = \"fulfilled\";\n            this.promise._inspect.value = value;\n          }\n        }\n\n        this.native_resolve(value);\n      }\n    }\n  }, {\n    key: \"fulfill\",\n    value: function fulfill(value) {\n      if (isPromiseAlike(value)) {\n        throw notImplementedError(\"fulfill(thenable)\");\n      }\n\n      this.promise._inspect.state = \"fulfilled\";\n      this.promise._inspect.value = value;\n      this.native_resolve(value);\n    }\n  }, {\n    key: \"reject\",\n    value: function reject(reason) {\n      this.promise._inspect.state = \"rejected\";\n      this.promise._inspect.reason = reason;\n      this.native_reject(reason);\n    }\n  }]);\n\n  return Deferred;\n}();\n\nnotImplemented(Deferred.prototype, \"notify\");\n/**\n * Constructs a {promise, resolve, reject} object.\n *\n * `resolve` is a callback to invoke with a more resolved value for the\n * promise. To fulfill the promise, invoke `resolve` with any value that is\n * not a thenable. To reject the promise, invoke `resolve` with a rejected\n * thenable, or invoke `reject` with the reason directly. To resolve the\n * promise to another thenable, thus putting it in the same state, invoke\n * `resolve` with that other thenable.\n */\n\nQ.defer = defer;\n\nfunction defer() {\n  return new Deferred();\n}\n/**\n * Creates a Node-style callback that will resolve or reject the deferred\n * promise.\n * @returns a nodeback\n */\n\n\nDeferred.prototype.makeNodeResolver = function () {\n  var self = this;\n  return function (error, value) {\n    if (error) {\n      self.reject(error);\n    } else if (arguments.length > 2) {\n      self.resolve(array_slice(arguments, 1));\n    } else {\n      self.resolve(value);\n    }\n  };\n};\n/**\n * @param resolver {Function} a function that returns nothing and accepts\n * the resolve, reject, and notify functions for a deferred.\n * @returns a promise that may be resolved with the given resolve and reject\n * functions, or rejected by a thrown exception in resolver\n */\n\n\nQ.Promise = promise; // ES6\n\nQ.promise = promise;\n\nfunction promise(resolver) {\n  if (typeof resolver !== \"function\") {\n    throw new TypeError(\"resolver must be a function.\");\n  }\n\n  var deferred = defer();\n\n  try {\n    resolver(deferred.resolve, deferred.reject);\n  } catch (reason) {\n    deferred.reject(reason);\n  }\n\n  return deferred.promise;\n}\n\npromise.resolve = Q; // ES6\n// XXX experimental.  This method is a way to denote that a local value is\n// serializable and should be immediately dispatched to a remote upon request,\n// instead of passing a reference.\n\nQ.passByCopy = function (object) {\n  //freeze(object);\n  //passByCopies.set(object, true);\n  return object;\n};\n\nQPromise.prototype.passByCopy = function () {\n  //freeze(object);\n  //passByCopies.set(object, true);\n  return this;\n};\n/**\n * If two promises eventually fulfill to the same value, promises that value,\n * but otherwise rejects.\n * @param x {Any*}\n * @param y {Any*}\n * @returns {Any*} a promise for x and y if they are the same, but a rejection\n * otherwise.\n *\n */\n\n\nQP_export(\"join\", function (that) {\n  return Q([this, that]).spread(function (x, y) {\n    if (x === y) {\n      // TODO: \"===\" should be Object.is or equiv\n      return x;\n    } else {\n      throw new Error(\"Q can't join: not the same: \" + x + \" \" + y);\n    }\n  });\n});\n/**\n * Returns a promise for the first of an array of promises to become settled.\n * @param answers {Array[Any*]} promises to race\n * @returns {Any*} the first promise to be settled\n */\n\nQP_export(\"race\", function () {\n  return this.then(function (promises) {\n    return Promise.race(promises);\n  });\n});\npromise.race = Q.race; // ES6\n\n/**\n * Constructs a Promise with a promise descriptor object and optional fallback\n * function.  The descriptor contains methods like when(rejected), get(name),\n * set(name, value), post(name, args), and delete(name), which all\n * return either a value, a promise for a value, or a rejection.  The fallback\n * accepts the operation name, a resolver, and any further arguments that would\n * have been forwarded to the appropriate method above had a method been\n * provided with the proper name.  The API makes no guarantees about the nature\n * of the returned object, apart from that it is usable whereever promises are\n * bought and sold.\n */\n\nnotImplemented(Q, \"makePromise\");\nQ.fromNative = fromNative;\n\nfunction fromNative(p) {\n  return new QPromise(p, {\n    state: \"pending\"\n  });\n}\n\nfunction toNativeReturn(fun) {\n  if (!(fun instanceof Function)) {\n    return undefined;\n  }\n\n  return function () {\n    var ret = fun.apply(this, arguments);\n\n    if (ret instanceof QPromise) {\n      return ret._native;\n    } else {\n      return ret;\n    }\n  };\n}\n\nQ.QPromise = QPromise;\n\nQPromise.prototype.inspect = function () {\n  return this._inspect;\n};\n\nQPromise.prototype.toString = function () {\n  return \"[object QPromise]\";\n};\n\nQPromise.prototype.then = function (fulfilled, rejected) {\n  return fromNative(this._native.then(toNativeReturn(fulfilled), toNativeReturn(rejected)));\n};\n/**\n * Works almost like \"finally\", but not called for rejections.\n * Original resolution value is passed through callback unaffected.\n * Callback may return a promise that will be awaited for.\n * @param {Function} callback\n * @returns {Q.Promise}\n * @example\n * doSomething()\n *   .then(...)\n *   .tap(console.log)\n *   .then(...);\n */\n\n\nQP_export(\"tap\", function (callback) {\n  callback = Q(callback);\n  return this.then(function (value) {\n    return callback.fcall(value).thenResolve(value);\n  });\n});\n/**\n * Registers an observer on a promise.\n *\n * Guarantees:\n *\n * 1. that fulfilled and rejected will be called only once.\n * 2. that either the fulfilled callback or the rejected callback will be\n *    called, but not both.\n * 3. that fulfilled and rejected will not be called in this turn.\n *\n * @param value      promise or immediate reference to observe\n * @param fulfilled  function to be called with the fulfilled value\n * @param rejected   function to be called with the rejection exception\n * @return promise for the return value from the invoked callback\n */\n\nQ.when = function (value, fulfilled, rejected) {\n  return Q(value).then(fulfilled, rejected);\n};\n\nQP_export(\"thenResolve\", function (value) {\n  return this.then(function () {\n    return value;\n  });\n});\nQP_export(\"thenReject\", function (reason) {\n  return this.then(function () {\n    throw reason;\n  });\n});\n/**\n * If an object is not a promise, it is as \"near\" as possible.\n * If a promise is rejected, it is as \"near\" as possible too.\n * If it’s a fulfilled promise, the fulfillment value is nearer.\n * If it’s a deferred promise and the deferred has been resolved, the\n * resolution is \"nearer\".\n * @param object\n * @returns most resolved (nearest) form of the object\n */\n// XXX should we re-do this?\n\nQ.nearer = nearer;\n\nfunction nearer(value) {\n  if (isPromise(value)) {\n    var inspected = value.inspect();\n\n    if (inspected.state === \"fulfilled\") {\n      return inspected.value;\n    }\n  }\n\n  return value;\n}\n/**\n * @returns whether the given object is a promise.\n * Otherwise it is a fulfilled value.\n */\n\n\nQ.isPromise = isPromise;\n\nfunction isPromise(object) {\n  return object instanceof QPromise;\n}\n\nQ.isPromiseAlike = isPromiseAlike;\n\nfunction isPromiseAlike(object) {\n  return isObject(object) && typeof object.then === \"function\";\n}\n/**\n * @returns whether the given object is a pending promise, meaning not\n * fulfilled or rejected.\n */\n\n\nQ.isPending = function (object) {\n  return isPromise(object) && object.isPending();\n};\n\nQPromise.prototype.isPending = function () {\n  return this.inspect().state === \"pending\";\n};\n/**\n * @returns whether the given object is a value or fulfilled\n * promise.\n */\n\n\nQ.isFulfilled = function (object) {\n  return !isPromise(object) || object.isFulfilled();\n};\n\nQPromise.prototype.isFulfilled = function () {\n  return this.inspect().state === \"fulfilled\";\n};\n/**\n * @returns whether the given object is a rejected promise.\n */\n\n\nQ.isRejected = function (object) {\n  return isPromise(object) && object.isRejected();\n};\n\nQPromise.prototype.isRejected = function () {\n  return this.inspect().state === \"rejected\";\n};\n\nvar trackUnhandledRejections = true;\nnotImplemented(Q, \"resetUnhandledRejections\");\nnotImplemented(Q, \"getUnhandledReasons\");\n\nQ.stopUnhandledRejectionTracking = function () {\n  trackUnhandledRejections = false;\n};\n/**\n * Constructs a rejected promise.\n * @param reason value describing the failure\n */\n\n\nQ.reject = function (reason) {\n  return new QPromise(Promise.reject(reason), {\n    state: \"rejected\",\n    reason: reason\n  });\n};\n\npromise.reject = Q.reject; // ES6\n\n/**\n * Constructs a fulfilled promise for an immediate reference.\n * @param value immediate reference\n */\n\nQ.fulfill = function (value) {\n  if (isPromiseAlike(value)) {\n    throw notImplementedError(\"fulfill(thenable)\");\n  } else {\n    return new QPromise(Promise.resolve(value), {\n      state: \"fulfilled\",\n      value: value\n    });\n  }\n};\n/**\n * Converts thenables to Q promises.\n * @param promise thenable promise\n * @returns a Q promise\n */\n\n\nfunction coerce(promise) {\n  return new QPromise(Promise.resolve(promise), {\n    state: \"pending\"\n  });\n}\n/**\n * Annotates an object such that it will never be\n * transferred away from this process over any promise\n * communication channel.\n * @param object\n * @returns promise a wrapping of that object that\n * additionally responds to the \"isDef\" message\n * without a rejection.\n */\n\n\nnotImplemented(Q, \"master\");\n/**\n * Spreads the values of a promised array of arguments into the\n * fulfillment callback.\n * @param fulfilled callback that receives variadic arguments from the\n * promised array\n * @param rejected callback that receives the exception if the promise\n * is rejected.\n * @returns a promise for the return value or thrown exception of\n * either callback.\n */\n\nQP_export(\"spread\", function (fulfilled, rejected) {\n  return this.all().then(function (array) {\n    return fulfilled.apply(void 0, array);\n  }, rejected);\n});\n/**\n * The async function is a decorator for generator functions, turning\n * them into asynchronous generators.  Although generators are only part\n * of the newest ECMAScript 6 drafts, this code does not cause syntax\n * errors in older engines.  This code should continue to work and will\n * in fact improve over time as the language improves.\n *\n * ES6 generators are currently part of V8 version 3.19 with the\n * --harmony-generators runtime flag enabled.  SpiderMonkey has had them\n * for longer, but under an older Python-inspired form.  This function\n * works on both kinds of generators.\n *\n * Decorates a generator function such that:\n *  - it may yield promises\n *  - execution will continue when that promise is fulfilled\n *  - the value of the yield expression will be the fulfilled value\n *  - it returns a promise for the return value (when the generator\n *    stops iterating)\n *  - the decorated function returns a promise for the return value\n *    of the generator or the first rejected promise among those\n *    yielded.\n *  - if an error is thrown in the generator, it propagates through\n *    every following yield until it is caught, or until it escapes\n *    the generator function altogether, and is translated into a\n *    rejection for the promise returned by the decorated generator.\n */\n\nQ.async = function (makeGenerator) {\n  return function () {\n    // when verb is \"send\", arg is a value\n    // when verb is \"throw\", arg is an exception\n    function continuer(verb, arg) {\n      var result; // Until V8 3.19 / Chromium 29 is released, SpiderMonkey is the only\n      // engine that has a deployed base of browsers that support generators.\n      // However, SM's generators use the Python-inspired semantics of\n      // outdated ES6 drafts.  We would like to support ES6, but we'd also\n      // like to make it possible to use generators in deployed browsers, so\n      // we also support Python-style generators.  At some point we can remove\n      // this block.\n\n      if (typeof StopIteration === \"undefined\") {\n        // ES6 Generators\n        try {\n          result = generator[verb](arg);\n        } catch (exception) {\n          return Q.reject(exception);\n        }\n\n        if (result.done) {\n          return Q(result.value);\n        } else {\n          return Q(result.value).then(callback, errback);\n        }\n      } else {\n        // SpiderMonkey Generators\n        // FIXME: Remove this case when SM does ES6 generators.\n        try {\n          result = generator[verb](arg);\n        } catch (exception) {\n          if (isStopIteration(exception)) {\n            return Q(exception.value);\n          } else {\n            return Q.reject(exception);\n          }\n        }\n\n        return Q(result).then(callback, errback);\n      }\n    }\n\n    var generator = makeGenerator.apply(this, arguments);\n    var callback = continuer.bind(continuer, \"next\");\n    var errback = continuer.bind(continuer, \"throw\");\n    return callback();\n  };\n};\n/**\n * The spawn function is a small wrapper around async that immediately\n * calls the generator and also ends the promise chain, so that any\n * unhandled errors are thrown instead of forwarded to the error\n * handler. This is useful because it's extremely common to run\n * generators at the top-level to work with libraries.\n */\n\n\nQ.spawn = function (makeGenerator) {\n  Q.done(Q.async(makeGenerator)());\n}; // FIXME: Remove this interface once ES6 generators are in SpiderMonkey.\n\n/**\n * Throws a ReturnValue exception to stop an asynchronous generator.\n *\n * This interface is a stop-gap measure to support generator return\n * values in older Firefox/SpiderMonkey.  In browsers that support ES6\n * generators like Chromium 29, just use \"return\" in your generator\n * functions.\n *\n * @param value the return value for the surrounding generator\n * @throws ReturnValue exception with the value.\n * @example\n * // ES6 style\n * Q.async(function* () {\n *      var foo = yield getFooPromise();\n *      var bar = yield getBarPromise();\n *      return foo + bar;\n * })\n * // Older SpiderMonkey style\n * Q.async(function () {\n *      var foo = yield getFooPromise();\n *      var bar = yield getBarPromise();\n *      Q.return(foo + bar);\n * })\n */\n\n\nQ[\"return\"] = function (value) {\n  throw new QReturnValue(value);\n};\n/**\n * The promised function decorator ensures that any promise arguments\n * are settled and passed as values (`this` is also settled and passed\n * as a value).  It will also ensure that the result of a function is\n * always a promise.\n *\n * @example\n * var add = Q.promised(function (a, b) {\n *     return a + b;\n * });\n * add(Q(a), Q(B));\n *\n * @param {function} callback The function to decorate\n * @returns {function} a function that has been decorated.\n */\n\n\nQ.promised = function (callback) {\n  return function () {\n    return Q.spread([this, Q.all(arguments)], function (self, args) {\n      return callback.apply(self, args);\n    });\n  };\n};\n/**\n * sends a message to a value in a future turn\n * @param object* the recipient\n * @param op the name of the message operation, e.g., \"when\",\n * @param args further arguments to be forwarded to the operation\n * @returns result {Promise} a promise for the result of the operation\n */\n\n\nnotImplemented(Q, \"dispatch\");\nnotImplemented(QPromise.prototype, \"dispatch\");\n/**\n * Gets the value of a property in a future turn.\n * @param object    promise or immediate reference for target object\n * @param name      name of property to get\n * @return promise for the property value\n */\n\nQP_export(\"get\", function (key) {\n  return this.then(function (value) {\n    return value[key];\n  });\n});\n/**\n * Sets the value of a property in a future turn.\n * @param object    promise or immediate reference for object object\n * @param name      name of property to set\n * @param value     new value of property\n * @return promise for the return value\n */\n\nQP_export(\"set\", function (key, rhs) {\n  return this.then(function (value) {\n    value[key] = rhs;\n  });\n});\n/**\n * Deletes a property in a future turn.\n * @param object    promise or immediate reference for target object\n * @param name      name of property to delete\n * @return promise for the return value\n */\n\nQP_export([\"del\", \"delete\"], function (key) {\n  return this.then(function (value) {\n    delete value[key];\n  });\n});\n/**\n * Invokes a method in a future turn.\n * @param object    promise or immediate reference for target object\n * @param name      name of method to invoke\n * @param value     a value to post, typically an array of\n *                  invocation arguments for promises that\n *                  are ultimately backed with `resolve` values,\n *                  as opposed to those backed with URLs\n *                  wherein the posted value can be any\n *                  JSON serializable object.\n * @return promise for the return value\n */\n// bound locally because it is used by other methods\n\nQP_export([\"mapply\", \"post\"], function (name, args) {\n  return this.then(function (value) {\n    // Mark Miller proposes that post with no name should apply a\n    // promised function.\n    if (name === null || name === void 0) {\n      return value.apply(void 0, args);\n    } else {\n      return value[name].apply(value, args);\n    }\n  });\n});\n/**\n * Invokes a method in a future turn.\n * @param object    promise or immediate reference for target object\n * @param name      name of method to invoke\n * @param ...args   array of invocation arguments\n * @return promise for the return value\n */\n\nQP_export([\"send\", \"mcall\", \"invoke\"], function (name\n/*...args*/\n) {\n  return this.post(name, array_slice(arguments, 1));\n});\n\nQPromise.prototype.apply = function (thisp, args) {\n  return this.then(function (value) {\n    return value.apply(thisp, args);\n  });\n};\n/**\n * Applies the promised function in a future turn.\n * @param object    promise or immediate reference for target function\n * @param args      array of application arguments\n */\n\n\nQP_export(\"fapply\", function (args) {\n  return this.apply(void 0, args);\n});\n/**\n * Calls the promised function in a future turn.\n * @param object    promise or immediate reference for target function\n * @param ...args   array of application arguments\n */\n\nQP_export([\"try\", \"fcall\"], function\n  /*...args*/\n() {\n  return this.apply(void 0, array_slice(arguments));\n});\n/**\n * Binds the promised function, transforming return values into a fulfilled\n * promise and thrown errors into a rejected one.\n * @param object    promise or immediate reference for target function\n * @param ...args   array of application arguments\n */\n\nQP_export(\"fbind\", function\n  /*...args*/\n() {\n  var promise = this;\n  var args = array_slice(arguments);\n  return function fbound() {\n    return promise.apply(this, args.concat(array_slice(arguments)));\n  };\n});\n/**\n * Requests the names of the owned properties of a promised\n * object in a future turn.\n * @param object    promise or immediate reference for target object\n * @return promise for the keys of the eventually settled object\n */\n\nQP_export(\"keys\", function () {\n  return this.then(function (value) {\n    return Object.keys(value);\n  });\n});\n/**\n * Turns an array of promises into a promise for an array.  If any of\n * the promises gets rejected, the whole array is rejected immediately.\n * @param {Array*} an array (or promise for an array) of values (or\n * promises for values)\n * @returns a promise for an array of the corresponding values\n */\n// By Mark Miller\n// http://wiki.ecmascript.org/doku.php?id=strawman:concurrency&rev=1308776521#allfulfilled\n\nQP_export(\"all\", function () {\n  return this.then(function (rpromises) {\n    return Promise.all(rpromises).then(function (rvalues) {\n      // Q.all is specified to modify and return the input array\n      rpromises.length = 0;\n      Array.prototype.push.apply(rpromises, rvalues);\n      return rpromises;\n    });\n  });\n});\npromise.all = Q.all; // ES6\n\n/**\n * Returns the first resolved promise of an array. Prior rejected promises are\n * ignored.  Rejects only if all promises are rejected.\n * @param {Array*} an array containing values or promises for values\n * @returns a promise fulfilled with the value of the first resolved promise,\n * or a rejected promise if all promises are rejected.\n */\n\nQ.any = any;\n\nfunction any(promises) {\n  if (promises.length === 0) {\n    return Q.resolve();\n  }\n\n  var deferred = Q.defer();\n  var pendingCount = 0;\n  array_reduce(promises, function (prev, current, index) {\n    var promise = promises[index];\n    pendingCount++;\n    Q(promise).then(onFulfilled, onRejected);\n\n    function onFulfilled(result) {\n      deferred.resolve(result);\n    }\n\n    function onRejected(err) {\n      pendingCount--;\n\n      if (pendingCount === 0) {\n        var rejection = err || new Error(\"\" + err);\n        rejection.message = \"Q can't get fulfillment value from any promise, all \" + \"promises were rejected. Last error message: \" + rejection.message;\n        deferred.reject(rejection);\n      }\n    }\n  }, undefined);\n  return deferred.promise;\n}\n\nQPromise.prototype.any = function () {\n  return any(this);\n};\n/**\n * Waits for all promises to be settled, either fulfilled or\n * rejected.  This is distinct from `all` since that would stop\n * waiting at the first rejection.  The promise returned by\n * `allResolved` will never be rejected.\n * @param promises a promise for an array (or an array) of promises\n * (or values)\n * @return a promise for an array of promises\n */\n\n\nQP_export(\"allResolved\", function () {\n  return this.then(function (promises) {\n    promises = array_map(promises, Q);\n    return Q.all(array_map(promises, function (promise) {\n      return Q(promise).then(noop, noop);\n    })).then(function () {\n      return promises;\n    });\n  });\n});\n/**\n * Turns an array of promises into a promise for an array of their states (as\n * returned by `inspect`) when they have all settled.\n * @param {Array[Any*]} values an array (or promise for an array) of values (or\n * promises for values)\n * @returns {Array[State]} an array of states for the respective values.\n */\n\nQP_export(\"allSettled\", function () {\n  return this.then(function (promises) {\n    return Q.all(array_map(promises, function (promise) {\n      promise = Q(promise);\n\n      function regardless() {\n        return promise.inspect();\n      }\n\n      return promise.then(regardless, regardless);\n    }));\n  });\n});\n/**\n * Captures the failure of a promise, giving an oportunity to recover\n * with a callback.  If the given promise is fulfilled, the returned\n * promise is fulfilled.\n * @param {Any*} promise for something\n * @param {Function} callback to fulfill the returned promise if the\n * given promise is rejected\n * @returns a promise for the return value of the callback\n */\n\nQP_export([\"fail\", \"catch\"], function (rejected) {\n  return fromNative(this._native[\"catch\"](toNativeReturn(rejected)));\n});\n/**\n * Attaches a listener that can respond to progress notifications from a\n * promise's originating deferred. This listener receives the exact arguments\n * passed to ``deferred.notify``.\n * @param {Any*} promise for something\n * @param {Function} callback to receive any progress notifications\n * @returns the given promise, unchanged\n */\n\nnotImplemented(Q, \"progress\");\nnotImplemented(QPromise.prototype, \"progress\");\n/**\n * Provides an opportunity to observe the settling of a promise,\n * regardless of whether the promise is fulfilled or rejected.  Forwards\n * the resolution to the returned promise when the callback is done.\n * The callback can return a promise to defer completion.\n * @param {Any*} promise\n * @param {Function} callback to observe the resolution of the given\n * promise, takes no arguments.\n * @returns a promise for the resolution of the given promise when\n * ``fin`` is done.\n */\n\nQP_export([\"fin\", \"finally\"], function (callback) {\n  if (this._native[\"finally\"] && typeof callback === \"function\") {\n    return fromNative(this._native[\"finally\"](toNativeReturn(callback)));\n  }\n\n  if (!callback || typeof callback.apply !== \"function\") {\n    throw new Error(\"Q can't apply finally callback\");\n  }\n\n  callback = Q(callback);\n  return this.then(function (value) {\n    return callback.fcall().then(function () {\n      return value;\n    });\n  }, function (reason) {\n    // TODO attempt to recycle the rejection with \"this\".\n    return callback.fcall().then(function () {\n      throw reason;\n    });\n  });\n});\n/**\n * Terminates a chain of promises, forcing rejections to be\n * thrown as exceptions.\n * @param {Any*} promise at the end of a chain of promises\n * @returns nothing\n */\n\nQP_export(\"done\", function (fulfilled, rejected) {\n  var onUnhandledError = function onUnhandledError(error) {\n    if (Q.onerror) {\n      Q.onerror(error);\n    } else {\n      throw error;\n    }\n  }; // Avoid unnecessary `nextTick`ing via an unnecessary `when`.\n\n\n  var promise = fulfilled || rejected ? this.then(fulfilled, rejected) : this;\n\n  promise._native.then(void 0, onUnhandledError);\n});\n/**\n * Causes a promise to be rejected if it does not get fulfilled before\n * some milliseconds time out.\n * @param {Any*} promise\n * @param {Number} milliseconds timeout\n * @param {Any*} custom error message or Error object (optional)\n * @returns a promise for the resolution of the given promise if it is\n * fulfilled before the timeout, otherwise rejected.\n */\n\nQP_export(\"timeout\", function (ms, error) {\n  var deferred = defer();\n  var timeoutId = setTimeout(function () {\n    if (!error || \"string\" === typeof error) {\n      error = new Error(error || \"Timed out after \" + ms + \" ms\");\n      error.code = \"ETIMEDOUT\";\n    }\n\n    deferred.reject(error);\n  }, ms);\n  this.then(function (value) {\n    clearTimeout(timeoutId);\n    deferred.resolve(value);\n  }, function (exception) {\n    clearTimeout(timeoutId);\n    deferred.reject(exception);\n  });\n  return deferred.promise;\n});\n/**\n * Returns a promise for the given value (or promised value), some\n * milliseconds after it resolved. Passes rejections immediately.\n * @param {Any*} promise\n * @param {Number} milliseconds\n * @returns a promise for the resolution of the given promise after milliseconds\n * time has elapsed since the resolution of the given promise.\n * If the given promise rejects, that is passed immediately.\n */\n\nQ.delay = function (object, timeout) {\n  if (timeout === void 0) {\n    timeout = object;\n    object = void 0;\n  }\n\n  return Q(object).delay(timeout);\n};\n\nQPromise.prototype.delay = function (timeout) {\n  return this.then(function (value) {\n    var deferred = defer();\n    setTimeout(function () {\n      deferred.resolve(value);\n    }, timeout);\n    return deferred.promise;\n  });\n};\n/**\n * Passes a continuation to a Node function, which is called with the given\n * arguments provided as an array, and returns a promise.\n *\n *      Q.nfapply(FS.readFile, [__filename])\n *      .then(function (content) {\n *      })\n *\n */\n\n\nQP_export(\"nfapply\", function (args) {\n  var deferred = defer();\n  var nodeArgs = array_slice(args);\n  nodeArgs.push(deferred.makeNodeResolver());\n  this.fapply(nodeArgs).fail(deferred.reject);\n  return deferred.promise;\n});\n/**\n * Passes a continuation to a Node function, which is called with the given\n * arguments provided individually, and returns a promise.\n * @example\n * Q.nfcall(FS.readFile, __filename)\n * .then(function (content) {\n * })\n *\n */\n\nQP_export(\"nfcall\", function\n  /*...args*/\n() {\n  var nodeArgs = array_slice(arguments);\n  var deferred = defer();\n  nodeArgs.push(deferred.makeNodeResolver());\n  this.fapply(nodeArgs).fail(deferred.reject);\n  return deferred.promise;\n});\n/**\n * Wraps a NodeJS continuation passing function and returns an equivalent\n * version that returns a promise.\n * @example\n * Q.nfbind(FS.readFile, __filename)(\"utf-8\")\n * .then(console.log)\n * .done()\n */\n\nQP_export([\"nfbind\", \"denodeify\"], function\n  /*...args*/\n() {\n  var callback = this;\n  var baseArgs = array_slice(arguments);\n  return function () {\n    var nodeArgs = baseArgs.concat(array_slice(arguments));\n    var deferred = defer();\n    nodeArgs.push(deferred.makeNodeResolver());\n    callback.fapply(nodeArgs).fail(deferred.reject);\n    return deferred.promise;\n  };\n});\n\nQ.nbind = function (callback, thisp\n/*...args*/\n) {\n  var baseArgs = array_slice(arguments, 2);\n  return function () {\n    var nodeArgs = baseArgs.concat(array_slice(arguments));\n    var deferred = defer();\n    nodeArgs.push(deferred.makeNodeResolver());\n\n    function bound() {\n      return callback.apply(thisp, arguments);\n    }\n\n    Q(bound).fapply(nodeArgs).fail(deferred.reject);\n    return deferred.promise;\n  };\n};\n\nQPromise.prototype.nbind = function\n  /*thisp, ...args*/\n() {\n  var args = array_slice(arguments, 0);\n  args.unshift(this);\n  return Q.nbind.apply(void 0, args);\n};\n/**\n * Calls a method of a Node-style object that accepts a Node-style\n * callback with a given array of arguments, plus a provided callback.\n * @param object an object that has the named method\n * @param {String} name name of the method of object\n * @param {Array} args arguments to pass to the method; the callback\n * will be provided by Q and appended to these arguments.\n * @returns a promise for the value or error\n */\n\n\nQP_export([\"nmapply\", \"npost\"], function (name, args) {\n  var nodeArgs = array_slice(args || []);\n  var deferred = defer();\n  nodeArgs.push(deferred.makeNodeResolver());\n  this.post(name, nodeArgs).fail(deferred.reject);\n  return deferred.promise;\n});\n/**\n * Calls a method of a Node-style object that accepts a Node-style\n * callback, forwarding the given variadic arguments, plus a provided\n * callback argument.\n * @param object an object that has the named method\n * @param {String} name name of the method of object\n * @param ...args arguments to pass to the method; the callback will\n * be provided by Q and appended to these arguments.\n * @returns a promise for the value or error\n */\n\nQP_export([\"nsend\", \"nmcall\", \"ninvoke\"], function (name\n/*...args*/\n) {\n  var nodeArgs = array_slice(arguments, 1);\n  var deferred = defer();\n  nodeArgs.push(deferred.makeNodeResolver());\n  this.post(name, nodeArgs).fail(deferred.reject);\n  return deferred.promise;\n});\n/**\n * If a function would like to support both Node continuation-passing-style and\n * promise-returning-style, it can end its internal promise chain with\n * `nodeify(nodeback)`, forwarding the optional nodeback argument.  If the user\n * elects to use a nodeback, the result will be sent there.  If they do not\n * pass a nodeback, they will receive the result promise.\n * @param object a result (or a promise for a result)\n * @param {Function} nodeback a Node.js-style callback\n * @returns either the promise or nothing\n */\n\nQP_export(\"nodeify\", function (nodeback) {\n  if (nodeback) {\n    this.done(function (value) {\n      nodeback(null, value);\n    }, function (error) {\n      nodeback(error);\n    });\n  } else {\n    return this;\n  }\n});\n\nQ.noConflict = function () {\n  throw new Error(\"Q.noConflict only works when Q is used as a global\");\n};"]}