{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/6841","repository_url":"https://api.github.com/repos/nim-lang/Nim","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/6841/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/6841/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/6841/events","html_url":"https://github.com/nim-lang/Nim/pull/6841","id":277712051,"number":6841,"title":"A demonstration of my approach for JS async","user":{"login":"alehander42","id":830715,"avatar_url":"https://avatars1.githubusercontent.com/u/830715?v=4","gravatar_id":"","url":"https://api.github.com/users/alehander42","html_url":"https://github.com/alehander42","followers_url":"https://api.github.com/users/alehander42/followers","following_url":"https://api.github.com/users/alehander42/following{/other_user}","gists_url":"https://api.github.com/users/alehander42/gists{/gist_id}","starred_url":"https://api.github.com/users/alehander42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alehander42/subscriptions","organizations_url":"https://api.github.com/users/alehander42/orgs","repos_url":"https://api.github.com/users/alehander42/repos","events_url":"https://api.github.com/users/alehander42/events{/privacy}","received_events_url":"https://api.github.com/users/alehander42/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-11-29T11:01:43Z","updated_at":"2017-12-01T07:48:43Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/nim-lang/Nim/pulls/6841","html_url":"https://github.com/nim-lang/Nim/pull/6841","diff_url":"https://github.com/nim-lang/Nim/pull/6841.diff","patch_url":"https://github.com/nim-lang/Nim/pull/6841.patch"},"body":"Yesterday we had a discussion in the chat with @Araq , @dom96 and others about implementing some async support for the Nim's js target mapping to modern JS's async/await. (and eventually integrating an existing solution for compiling to older versions of js for people who need nim async in older js)\r\n\r\nI've already done something like this for a project of mine, so I open this PR to see if people agree with this approach.\r\n\r\nIt was easiest to just introduce an asyncjs module, which defines a js variant of`async`. \r\nIt replaces `return/result` inside with `return jsResolve(#) / result = jsResolve(#)` in order to satisfy the Future type (jsResolve(#) is generated as #, so no overhead).\r\n\r\nIt defines a function `await` in each body:\r\nthat seemed easier than the asyncmacro solution, because I didn't have to reimplement recognition of where to replace await nodes.  (I define it in each async body as a quick hack to make `await` out of `async` invalid)\r\n\r\nIn the end I generate `async` in jsgen for functions with `Future` return type. Overally it's a very simple approach which works for me in >100 async functions in an electron app written in Nim, however I am not sure if it seems suitable for upstream\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/348425599","html_url":"https://github.com/nim-lang/Nim/pull/6841#issuecomment-348425599","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/6841","id":348425599,"user":{"login":"alehander42","id":830715,"avatar_url":"https://avatars1.githubusercontent.com/u/830715?v=4","gravatar_id":"","url":"https://api.github.com/users/alehander42","html_url":"https://github.com/alehander42","followers_url":"https://api.github.com/users/alehander42/followers","following_url":"https://api.github.com/users/alehander42/following{/other_user}","gists_url":"https://api.github.com/users/alehander42/gists{/gist_id}","starred_url":"https://api.github.com/users/alehander42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alehander42/subscriptions","organizations_url":"https://api.github.com/users/alehander42/orgs","repos_url":"https://api.github.com/users/alehander42/repos","events_url":"https://api.github.com/users/alehander42/events{/privacy}","received_events_url":"https://api.github.com/users/alehander42/received_events","type":"User","site_admin":false},"created_at":"2017-12-01T07:48:43Z","updated_at":"2017-12-01T07:48:43Z","author_association":"CONTRIBUTOR","body":"I've added a PR https://github.com/nim-lang/Nim/pull/6851"}}
{"actor":{"display_login":"alehander42"}}