{"action":"created","issue":{"url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/627","repository_url":"https://api.github.com/repos/ruanyf/es6tutorial","labels_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/627/labels{/name}","comments_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/627/comments","events_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/627/events","html_url":"https://github.com/ruanyf/es6tutorial/issues/627","id":305399708,"number":627,"title":"关于promise和generate结合的那个例子的解释","user":{"login":"jialigit","id":13768484,"avatar_url":"https://avatars2.githubusercontent.com/u/13768484?v=4","gravatar_id":"","url":"https://api.github.com/users/jialigit","html_url":"https://github.com/jialigit","followers_url":"https://api.github.com/users/jialigit/followers","following_url":"https://api.github.com/users/jialigit/following{/other_user}","gists_url":"https://api.github.com/users/jialigit/gists{/gist_id}","starred_url":"https://api.github.com/users/jialigit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jialigit/subscriptions","organizations_url":"https://api.github.com/users/jialigit/orgs","repos_url":"https://api.github.com/users/jialigit/repos","events_url":"https://api.github.com/users/jialigit/events{/privacy}","received_events_url":"https://api.github.com/users/jialigit/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-15T03:05:00Z","updated_at":"2018-03-15T06:40:28Z","closed_at":"2018-03-15T06:40:28Z","author_association":"NONE","body":"在promise.doc 中关于promise和generator结合的例子：\r\nfunction getFoo () {\r\n  return new Promise(function (resolve, reject){\r\n    resolve('foo');\r\n  });\r\n}\r\n\r\nconst g = function* () {\r\n  try {\r\n    const foo = yield getFoo();\r\n    console.log(foo);\r\n  } catch (e) {\r\n    console.log(e);\r\n  }\r\n};\r\n\r\nfunction run (generator) {\r\n  const it = generator();\r\n\r\n  function go(result) {\r\n    console.log(\"result: \" + result);\r\n    if (result.done) {\r\n      console.log(\"done\" + result);\r\n      return result.value;\r\n    }\r\n\r\n    return result.value.then(function (value) {\r\n      console.log(\"value: \" + value);\r\n      return go(it.next(value));\r\n    }, function (error) {\r\n      return go(it.throw(error));\r\n    });\r\n  }\r\n\r\n  go(it.next());\r\n}\r\n\r\nrun(g);\r\n\r\n\r\n-----------------------------------这是分割线------------------------------\r\n中，run函数的go方法体中：\r\n function go(result) {\r\n    console.log(\"result: \" + result);\r\n    if (result.done) {\r\n      console.log(\"done\" + result);\r\n      return result.value;\r\n    }\r\n\r\n    return result.value.then(function (value) {\r\n      console.log(\"value: \" + value);\r\n      return go(it.next(value));\r\n    }, function (error) {\r\n      return go(it.throw(error));\r\n    });\r\n  }\r\n\r\n的参数result.done, result.value是什么？有点不明白，可否加上一些解释的内容？\r\n"},"comment":{"url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/comments/373276139","html_url":"https://github.com/ruanyf/es6tutorial/issues/627#issuecomment-373276139","issue_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/627","id":373276139,"user":{"login":"ruanyf","id":905434,"avatar_url":"https://avatars0.githubusercontent.com/u/905434?v=4","gravatar_id":"","url":"https://api.github.com/users/ruanyf","html_url":"https://github.com/ruanyf","followers_url":"https://api.github.com/users/ruanyf/followers","following_url":"https://api.github.com/users/ruanyf/following{/other_user}","gists_url":"https://api.github.com/users/ruanyf/gists{/gist_id}","starred_url":"https://api.github.com/users/ruanyf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruanyf/subscriptions","organizations_url":"https://api.github.com/users/ruanyf/orgs","repos_url":"https://api.github.com/users/ruanyf/repos","events_url":"https://api.github.com/users/ruanyf/events{/privacy}","received_events_url":"https://api.github.com/users/ruanyf/received_events","type":"User","site_admin":false},"created_at":"2018-03-15T06:40:28Z","updated_at":"2018-03-15T06:40:28Z","author_association":"OWNER","body":"next 方法返回的是一个 Iterator 对象，value 和 done 都是 Iterator 的属性，你可以参考 Iterator 那一章。"}}
{"actor":{"display_login":"ruanyf"}}