{"action":"created","issue":{"url":"https://api.github.com/repos/evshiron/node-async-flow/issues/3","repository_url":"https://api.github.com/repos/evshiron/node-async-flow","labels_url":"https://api.github.com/repos/evshiron/node-async-flow/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/evshiron/node-async-flow/issues/3/comments","events_url":"https://api.github.com/repos/evshiron/node-async-flow/issues/3/events","html_url":"https://github.com/evshiron/node-async-flow/issues/3","id":164004651,"number":3,"title":"return value","user":{"login":"stkap","id":2866997,"avatar_url":"https://avatars.githubusercontent.com/u/2866997?v=3","gravatar_id":"","url":"https://api.github.com/users/stkap","html_url":"https://github.com/stkap","followers_url":"https://api.github.com/users/stkap/followers","following_url":"https://api.github.com/users/stkap/following{/other_user}","gists_url":"https://api.github.com/users/stkap/gists{/gist_id}","starred_url":"https://api.github.com/users/stkap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stkap/subscriptions","organizations_url":"https://api.github.com/users/stkap/orgs","repos_url":"https://api.github.com/users/stkap/repos","events_url":"https://api.github.com/users/stkap/events{/privacy}","received_events_url":"https://api.github.com/users/stkap/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-06T06:07:17Z","updated_at":"2016-07-07T01:42:55Z","closed_at":null,"body":"Is it possible return value from Flow?\r\nFor example:  var x=Flow(function*(cb){ return 'World';});\r\n"},"comment":{"url":"https://api.github.com/repos/evshiron/node-async-flow/issues/comments/230956602","html_url":"https://github.com/evshiron/node-async-flow/issues/3#issuecomment-230956602","issue_url":"https://api.github.com/repos/evshiron/node-async-flow/issues/3","id":230956602,"user":{"login":"evshiron","id":8800643,"avatar_url":"https://avatars.githubusercontent.com/u/8800643?v=3","gravatar_id":"","url":"https://api.github.com/users/evshiron","html_url":"https://github.com/evshiron","followers_url":"https://api.github.com/users/evshiron/followers","following_url":"https://api.github.com/users/evshiron/following{/other_user}","gists_url":"https://api.github.com/users/evshiron/gists{/gist_id}","starred_url":"https://api.github.com/users/evshiron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evshiron/subscriptions","organizations_url":"https://api.github.com/users/evshiron/orgs","repos_url":"https://api.github.com/users/evshiron/repos","events_url":"https://api.github.com/users/evshiron/events{/privacy}","received_events_url":"https://api.github.com/users/evshiron/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T01:42:55Z","updated_at":"2016-07-07T01:42:55Z","body":"Yep, that should work.\r\nThe following code snippet demonstrates how to use `node-async-flow` with `express`:\r\n```javascript\r\n// Global helper functions?\r\nfunction getUserInfo(session, callback) {\r\n  return callback(null);\r\n}\r\nfunction handleError(res, { err, path }) {\r\n  return res.render('error', {\r\n    err, path,\r\n  });\r\n}\r\n\r\napp.get('/user', (req, res) => {\r\n  Flow(function*(cb) {\r\n\r\n    let err, user;\r\n\r\n    // Validate user session. A better practice is to do this in a middleware.\r\n    // If invalid, redirect and stop.\r\n    if(!req.session || !req.session.username) {\r\n      return res.redirect('/login');\r\n    }\r\n\r\n    // Do some async calls.\r\n    // For example, get user information from a database.\r\n    [err, user] = yield getUserInfo(req.session, cb.expect(2));\r\n\r\n    // Error handling.\r\n    if(err) {\r\n      return handleError(res, {\r\n        err,\r\n        path: req.path,\r\n      });\r\n    }\r\n\r\n    // Calls to sync functions have nothing special.\r\n    let meta;\r\n    try {\r\n      meta = JSON.parse(user.meta);\r\n    }\r\n    catch(err) {\r\n      return handleError(res, {\r\n        err,\r\n        path: req.path,\r\n      });\r\n    }\r\n\r\n    const { username, nickname } = user;\r\n\r\n    // Final render.\r\n    return res.render('user', {\r\n      username, nickname, meta,\r\n    });\r\n\r\n  });\r\n});\r\n```\r\n\r\nTo be aware, `Flow` itself is an async function, any bad practices to async functions apply to `node-async-flow` as well. Also, `node-async-flow` enable returning variables into a large single scope, as a result naming conflicts will appear as your application grows.\r\nI have many node.js projects and if there is `node-async-flow` or `evshiron/node-flow` as a dependency in `package.json`, it's used somewhere in the code. Also there are example links in the README of `node-async-flow`.\r\nFeel free to ask if you have further questions :)"}}
{"actor":{"display_login":"evshiron"}}