{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/682","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/682/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/682/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/682/events","html_url":"https://github.com/petkaantonov/bluebird/issues/682","id":92210236,"number":682,"title":"bluebird circular promise error while q-promise works","user":{"login":"Ajkcki","id":8405102,"avatar_url":"https://avatars.githubusercontent.com/u/8405102?v=3","gravatar_id":"","url":"https://api.github.com/users/Ajkcki","html_url":"https://github.com/Ajkcki","followers_url":"https://api.github.com/users/Ajkcki/followers","following_url":"https://api.github.com/users/Ajkcki/following{/other_user}","gists_url":"https://api.github.com/users/Ajkcki/gists{/gist_id}","starred_url":"https://api.github.com/users/Ajkcki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ajkcki/subscriptions","organizations_url":"https://api.github.com/users/Ajkcki/orgs","repos_url":"https://api.github.com/users/Ajkcki/repos","events_url":"https://api.github.com/users/Ajkcki/events{/privacy}","received_events_url":"https://api.github.com/users/Ajkcki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/2.0","name":"2.0","color":"e11d21"},{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/fix-in-progress","name":"fix-in-progress","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-30T21:56:55Z","updated_at":"2015-07-02T11:21:19Z","closed_at":null,"body":"The following  code uses q-library  to wrap PouchDB as a promise\r\n\r\n<pre>\r\nvar Promise = require(\"q\");\r\nvar PouchDB = require(\"pouchdb\");\r\nvar PouchdbPromise = (function () {\r\n    function PouchdbPromise(pouchdbName) {\r\n        this._pouchdbP = null;\r\n        this.pouchdbName = pouchdbName;\r\n    }\r\n    PouchdbPromise.prototype.getPouchdb = function () {\r\n        var self = this;\r\n        if (self._pouchdbP !== null)\r\n            return self._pouchdbP;\r\n        var deferred = Promise.defer();\r\n        try {\r\n            var _pouchdb = new PouchDB(self.pouchdbName);\r\n            deferred.resolve(_pouchdb);\r\n        }\r\n        catch (e) {\r\n            deferred.reject(\"Pouchdb init error:\" + e);\r\n        }\r\n        self._pouchdbP = deferred.promise;\r\n        return self._pouchdbP;\r\n    };\r\n    return PouchdbPromise;\r\n})();\r\n\r\nvar pdbP = new PouchdbPromise(\"abc\");\r\npdbP.getPouchdb().then(function (abc) {\r\n    abc.get(\"1\");\r\n});\r\n</pre>\r\nIt works fine. But switching to bluebird by changing the first line to\r\n<pre>\r\nvar Promise = require(\"bluebird\")\r\n</pre>\r\n\r\nleads to the following error:\r\n\r\n<pre>\r\nUnhandled rejection TypeError: circular promise resolution chain\r\n\r\n    See http://goo.gl/LhFpo0\r\n\r\n    at process._tickCallback (node.js:415:13)\r\nFrom previous event:\r\n    at PouchdbPromise.getPouchdb (SOMEDIR/app/scripts/playground/bluebird2.js:20:22)\r\n    at Object.<anonymous> (SOMEDIR/app/scripts/playground/bluebird2.js:31:6)\r\n    at Module._compile (module.js:456:26)\r\n    at Object.Module._extensions..js (module.js:474:10)\r\n    at Module.load (module.js:356:32)\r\n    at Function.Module._load (module.js:312:12)\r\n    at Function.Module.runMain (module.js:497:10)\r\n    at startup (node.js:119:16)\r\n    at node.js:902:3\r\n</pre>\r\n\r\nthe error was thrown at line 20 `deferred.resolve(_pouchdb)`. \r\n\r\n I know `Promise.defer()` is depreciated, using `new Promise` gets the same error. \r\n\r\nI also tried to run the code in a browser (Chrome 43), bluebird throws the same error and both q and Chrome's native promise work fine. I'm using bluebird version 2.9.30"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/118003754","html_url":"https://github.com/petkaantonov/bluebird/issues/682#issuecomment-118003754","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/682","id":118003754,"user":{"login":"bergus","id":1146478,"avatar_url":"https://avatars.githubusercontent.com/u/1146478?v=3","gravatar_id":"","url":"https://api.github.com/users/bergus","html_url":"https://github.com/bergus","followers_url":"https://api.github.com/users/bergus/followers","following_url":"https://api.github.com/users/bergus/following{/other_user}","gists_url":"https://api.github.com/users/bergus/gists{/gist_id}","starred_url":"https://api.github.com/users/bergus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bergus/subscriptions","organizations_url":"https://api.github.com/users/bergus/orgs","repos_url":"https://api.github.com/users/bergus/repos","events_url":"https://api.github.com/users/bergus/events{/privacy}","received_events_url":"https://api.github.com/users/bergus/received_events","type":"User","site_admin":false},"created_at":"2015-07-02T11:21:19Z","updated_at":"2015-07-02T11:21:19Z","body":"I meant to reply where I did :-) I don't think discussing this in a promisesaplus issue would have been wrong, even if the bug is invalid."}}