{"action":"created","issue":{"url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/68","repository_url":"https://api.github.com/repos/othiym23/node-continuation-local-storage","labels_url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/68/comments","events_url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/68/events","html_url":"https://github.com/othiym23/node-continuation-local-storage/pull/68","id":161049673,"number":68,"title":"`namespace.runReturn` method","user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-19T00:12:15Z","updated_at":"2016-06-19T15:31:39Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/pulls/68","html_url":"https://github.com/othiym23/node-continuation-local-storage/pull/68","diff_url":"https://github.com/othiym23/node-continuation-local-storage/pull/68.diff","patch_url":"https://github.com/othiym23/node-continuation-local-storage/pull/68.patch"},"body":"This PR adds a method `Namespace.prototype.runReturn`.\r\n\r\nIt's the same as `Namespace.prototype.run` except it returns the return value of the callback, rather than the context object.\r\n\r\nReduces boilerplate code when you need the return value of a function.\r\n\r\nThis is particularly useful when using promises. At present you need to do something like:\r\n\r\n```js\r\nfunction xxx() {\r\n    var promise;\r\n    ns.run( function() {\r\n        promise = Promise.resolve();\r\n    } );\r\n    return promise;\r\n}\r\n```\r\n\r\nThis PR would reduce it to:\r\n\r\n```js\r\nfunction xxx() {\r\n    return ns.runReturn( function() {\r\n        return Promise.resolve();\r\n    } );\r\n}\r\n```\r\n\r\nAlso makes for much cleaner code with coroutines e.g.:\r\n\r\n```js\r\nfunction* xxx() {\r\n    yield ns.runReturn( co.wrap( function*() {\r\n        yield Promise.resolve();\r\n    } ) );\r\n}\r\n```\r\n\r\nI'm not sure that the name `runReturn` is ideal. But I do feel this feature would be useful. I use CLS and promises above and am often having to use the workaround pattern.\r\n\r\nIf you were willing in principle, I'd need to add tests. But please advise which file(s) they should go in - I couldn't work out the best place for them."},"comment":{"url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/comments/227003440","html_url":"https://github.com/othiym23/node-continuation-local-storage/pull/68#issuecomment-227003440","issue_url":"https://api.github.com/repos/othiym23/node-continuation-local-storage/issues/68","id":227003440,"user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"created_at":"2016-06-19T15:31:39Z","updated_at":"2016-06-19T15:31:39Z","body":"By the way, most efficient pattern I've found with coroutines without `runReturn()` is:\r\n\r\n```js\r\nfunction* xxx() {\r\n    var promise;\r\n    ns.run( function() {\r\n        promise = co( function*() {\r\n            yield Promise.resolve();\r\n        } );\r\n    } );\r\n    yield promise;\r\n}\r\n```\r\n\r\nHorrible!"}}
{"actor":{"display_login":"overlookmotel"}}