{"action":"closed","issue":{"url":"https://api.github.com/repos/thunks/thunks/issues/2","labels_url":"https://api.github.com/repos/thunks/thunks/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/thunks/thunks/issues/2/comments","events_url":"https://api.github.com/repos/thunks/thunks/issues/2/events","html_url":"https://github.com/thunks/thunks/issues/2","id":38233419,"number":2,"title":"关于无缝接入第三方库","user":{"login":"simongfxu","id":2288388,"avatar_url":"https://avatars.githubusercontent.com/u/2288388?v=3","gravatar_id":"","url":"https://api.github.com/users/simongfxu","html_url":"https://github.com/simongfxu","followers_url":"https://api.github.com/users/simongfxu/followers","following_url":"https://api.github.com/users/simongfxu/following{/other_user}","gists_url":"https://api.github.com/users/simongfxu/gists{/gist_id}","starred_url":"https://api.github.com/users/simongfxu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simongfxu/subscriptions","organizations_url":"https://api.github.com/users/simongfxu/orgs","repos_url":"https://api.github.com/users/simongfxu/repos","events_url":"https://api.github.com/users/simongfxu/events{/privacy}","received_events_url":"https://api.github.com/users/simongfxu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-07-19T13:32:06Z","updated_at":"2015-10-13T00:51:28Z","closed_at":"2015-10-13T00:51:28Z","body":"比如bluebird有注明的[`promisifyAll`](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification)，对于像mongoose, redis这种第三方库，几乎不用修改任何代码就无缝接入Promise\r\n\r\n    // The most popular redis module\r\n    var Promise = require(\"bluebird\");\r\n    Promise.promisifyAll(require(\"redis\"));\r\n    \r\n    // Mongoose\r\n    var Promise = require(\"bluebird\");\r\n    Promise.promisifyAll(require(\"mongoose\"));\r\n\r\n业务代码的就可以像这样写了：\r\n\r\n    Feed.findOneAsync().then(function(feed){\r\n        feed.text = Math.random().toString()\r\n        return feed.saveAsync()\r\n    }).then(function(doc){\r\n        callback(null, doc)\r\n    })\r\n\r\nthunk这种基于封装的模式好像写起代码来，略显冗余和繁琐。\r\n\r\n目前我个人感觉就是如果业务比较复杂或者函数不太符合node.js callback风格的时候thunk还是挺有用的，不知道是否表达准确。\r\n\r\n"}}