{"action":"created","issue":{"url":"https://api.github.com/repos/tj/co/issues/272","repository_url":"https://api.github.com/repos/tj/co","labels_url":"https://api.github.com/repos/tj/co/issues/272/labels{/name}","comments_url":"https://api.github.com/repos/tj/co/issues/272/comments","events_url":"https://api.github.com/repos/tj/co/issues/272/events","html_url":"https://github.com/tj/co/issues/272","id":154091462,"number":272,"title":"Could we export toPromise?","user":{"login":"gunar","id":7684574,"avatar_url":"https://avatars.githubusercontent.com/u/7684574?v=3","gravatar_id":"","url":"https://api.github.com/users/gunar","html_url":"https://github.com/gunar","followers_url":"https://api.github.com/users/gunar/followers","following_url":"https://api.github.com/users/gunar/following{/other_user}","gists_url":"https://api.github.com/users/gunar/gists{/gist_id}","starred_url":"https://api.github.com/users/gunar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunar/subscriptions","organizations_url":"https://api.github.com/users/gunar/orgs","repos_url":"https://api.github.com/users/gunar/repos","events_url":"https://api.github.com/users/gunar/events{/privacy}","received_events_url":"https://api.github.com/users/gunar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-10T19:50:28Z","updated_at":"2016-05-11T22:34:13Z","closed_at":null,"body":"I'd like to use `co` but I'm not sure I can. I'm currently using generators, but not coroutines.\r\n\r\nWhat's the deal? I have generators that return strings. Eventually, my generators need to do some async stuff (db calls) before outputting those strings.\r\n\r\nCurrently I'm doing something very similar to `co`. That is, if the generator output `value` is a Promise, I chain it a `then` that passes the value back in. However, if the output is a string, I use it for other purposes.\r\n\r\ne.g.\r\n\r\n```js\r\nfunction *myGenerator(input) {\r\n  let step\r\n  const remoteVersion = yield 'Version: 0.0.1'\r\n  const remoteVersionFound = yield find(remoteVersion) // <- find returns a promise\r\n  if (remoteVersionFound !== undefined) = step yield 'Files: a, b, c'\r\n  else step = yield 'Not found'\r\n  // do stuff with \"step\"\r\n  return 'End'\r\n}\r\n\r\nconst instance = myGenerator()\r\ninstance.next()\r\nconst step = instance.next('Version: 0.0.2')\r\n// do stuff with \"step\"\r\n/// ...\r\n```\r\n\r\nSo, I'd like to rely on the community-built functions from `co` (e.g. `toPromise`). For that, I'd need `co` to export it.\r\n\r\nOR, could I use `co` in this situation?\r\n\r\nThanks a bunch!"},"comment":{"url":"https://api.github.com/repos/tj/co/issues/comments/218610402","html_url":"https://github.com/tj/co/issues/272#issuecomment-218610402","issue_url":"https://api.github.com/repos/tj/co/issues/272","id":218610402,"user":{"login":"LeonineKing1199","id":5543573,"avatar_url":"https://avatars.githubusercontent.com/u/5543573?v=3","gravatar_id":"","url":"https://api.github.com/users/LeonineKing1199","html_url":"https://github.com/LeonineKing1199","followers_url":"https://api.github.com/users/LeonineKing1199/followers","following_url":"https://api.github.com/users/LeonineKing1199/following{/other_user}","gists_url":"https://api.github.com/users/LeonineKing1199/gists{/gist_id}","starred_url":"https://api.github.com/users/LeonineKing1199/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeonineKing1199/subscriptions","organizations_url":"https://api.github.com/users/LeonineKing1199/orgs","repos_url":"https://api.github.com/users/LeonineKing1199/repos","events_url":"https://api.github.com/users/LeonineKing1199/events{/privacy}","received_events_url":"https://api.github.com/users/LeonineKing1199/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T22:34:13Z","updated_at":"2016-05-11T22:34:13Z","body":"Unless TJ wants to correct me, I don't think `co` will give you what you want. The beauty of `co` is that you don't have to call `.next()` repeatedly. You seem to actually want that and asuch, I don't think `co` is the tool for that job.\r\n\r\n`co` was more or less made for pure asynchronous control flow where you're never really calling the iterator directly. Instead, `co` takes whatever you give it and then it hooks back into your generator with whatever it did with what you gave it (resolving promises, executing thunks)."}}