{"action":"created","issue":{"url":"https://api.github.com/repos/yortus/asyncawait/issues/26","labels_url":"https://api.github.com/repos/yortus/asyncawait/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/yortus/asyncawait/issues/26/comments","events_url":"https://api.github.com/repos/yortus/asyncawait/issues/26/events","html_url":"https://github.com/yortus/asyncawait/issues/26","id":109190345,"number":26,"title":"async to callback","user":{"login":"yaronn","id":1359037,"avatar_url":"https://avatars.githubusercontent.com/u/1359037?v=3","gravatar_id":"","url":"https://api.github.com/users/yaronn","html_url":"https://github.com/yaronn","followers_url":"https://api.github.com/users/yaronn/followers","following_url":"https://api.github.com/users/yaronn/following{/other_user}","gists_url":"https://api.github.com/users/yaronn/gists{/gist_id}","starred_url":"https://api.github.com/users/yaronn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaronn/subscriptions","organizations_url":"https://api.github.com/users/yaronn/orgs","repos_url":"https://api.github.com/users/yaronn/repos","events_url":"https://api.github.com/users/yaronn/events{/privacy}","received_events_url":"https://api.github.com/users/yaronn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-30T22:09:18Z","updated_at":"2015-10-01T00:09:11Z","closed_at":null,"body":"I have a library written using the async/await pattern. I try to consume it from a library which uses callbacks. Here is a sample code:\r\n\r\n    var async = require('asyncawait/async');\r\n    var await = require('asyncawait/await');\r\n    var Promise = require('bluebird');\r\n\r\n    var foo = async (function() {\r\n        var resultA = await (Promise.promisify(bar));\r\n        return 111;\r\n    })\r\n\r\n    function bar(callback) {\r\n      setTimeout(callback, 2000)\r\n    }\r\n\r\n    function moo() {\r\n      var f = async.cps(foo)\r\n\r\n      f(function(err, res) {\r\n        console.log(res)\r\n      })\r\n\r\n    }\r\n\r\n    moo()\r\n\r\nI expected console.log to print 111 but instead it prints:\r\n\r\n    { _bitField: 0,\r\n      _fulfillmentHandler0: undefined,\r\n      _rejectionHandler0: undefined,\r\n      _progressHandler0: undefined,\r\n      _promise0: undefined,\r\n      _receiver0: undefined,\r\n      _settledValue: undefined }\r\n\r\nbtw if I inline foo in the async.cps line it works (but this is not an option since its an external library).\r\n\r\nAny idea?\r\n"},"comment":{"url":"https://api.github.com/repos/yortus/asyncawait/issues/comments/144578860","html_url":"https://github.com/yortus/asyncawait/issues/26#issuecomment-144578860","issue_url":"https://api.github.com/repos/yortus/asyncawait/issues/26","id":144578860,"user":{"login":"yortus","id":1252361,"avatar_url":"https://avatars.githubusercontent.com/u/1252361?v=3","gravatar_id":"","url":"https://api.github.com/users/yortus","html_url":"https://github.com/yortus","followers_url":"https://api.github.com/users/yortus/followers","following_url":"https://api.github.com/users/yortus/following{/other_user}","gists_url":"https://api.github.com/users/yortus/gists{/gist_id}","starred_url":"https://api.github.com/users/yortus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yortus/subscriptions","organizations_url":"https://api.github.com/users/yortus/orgs","repos_url":"https://api.github.com/users/yortus/repos","events_url":"https://api.github.com/users/yortus/events{/privacy}","received_events_url":"https://api.github.com/users/yortus/received_events","type":"User","site_admin":false},"created_at":"2015-10-01T00:09:11Z","updated_at":"2015-10-01T00:09:11Z","body":"Ah okay, then you don't have to change `foo`. So `foo` is just a function that returns a promise, and you want a function that takes a callback. You can either use something like [nodeify](https://www.npmjs.com/package/nodeify), or wrap it yourself like this:\r\n\r\n```javascript\r\nvar fooCps = async.cps (function() {\r\n    return await(foo());\r\n})\r\n```\r\n"}}