{"action":"created","issue":{"url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/10","repository_url":"https://api.github.com/repos/rbuckton/proposal-using-statement","labels_url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/10/comments","events_url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/10/events","html_url":"https://github.com/rbuckton/proposal-using-statement/issues/10","id":338059045,"node_id":"MDU6SXNzdWUzMzgwNTkwNDU=","number":10,"title":"how does this differ from for-of and the iteration protocol?","user":{"login":"michaelficarra","id":218840,"node_id":"MDQ6VXNlcjIxODg0MA==","avatar_url":"https://avatars1.githubusercontent.com/u/218840?v=4","gravatar_id":"","url":"https://api.github.com/users/michaelficarra","html_url":"https://github.com/michaelficarra","followers_url":"https://api.github.com/users/michaelficarra/followers","following_url":"https://api.github.com/users/michaelficarra/following{/other_user}","gists_url":"https://api.github.com/users/michaelficarra/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelficarra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelficarra/subscriptions","organizations_url":"https://api.github.com/users/michaelficarra/orgs","repos_url":"https://api.github.com/users/michaelficarra/repos","events_url":"https://api.github.com/users/michaelficarra/events{/privacy}","received_events_url":"https://api.github.com/users/michaelficarra/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-03T21:23:32Z","updated_at":"2018-07-11T19:16:17Z","closed_at":null,"author_association":"NONE","body":"I can safely acquire/release resources today with convenient syntax using for-of. In addition, the for-of also provides context for the release (throw vs return). What advantage does this proposal have?"},"comment":{"url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/comments/404280483","html_url":"https://github.com/rbuckton/proposal-using-statement/issues/10#issuecomment-404280483","issue_url":"https://api.github.com/repos/rbuckton/proposal-using-statement/issues/10","id":404280483,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNDI4MDQ4Mw==","user":{"login":"rbuckton","id":3902892,"node_id":"MDQ6VXNlcjM5MDI4OTI=","avatar_url":"https://avatars2.githubusercontent.com/u/3902892?v=4","gravatar_id":"","url":"https://api.github.com/users/rbuckton","html_url":"https://github.com/rbuckton","followers_url":"https://api.github.com/users/rbuckton/followers","following_url":"https://api.github.com/users/rbuckton/following{/other_user}","gists_url":"https://api.github.com/users/rbuckton/gists{/gist_id}","starred_url":"https://api.github.com/users/rbuckton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbuckton/subscriptions","organizations_url":"https://api.github.com/users/rbuckton/orgs","repos_url":"https://api.github.com/users/rbuckton/repos","events_url":"https://api.github.com/users/rbuckton/events{/privacy}","received_events_url":"https://api.github.com/users/rbuckton/received_events","type":"User","site_admin":false},"created_at":"2018-07-11T19:16:17Z","updated_at":"2018-07-11T19:16:17Z","author_association":"OWNER","body":"Using `for..of` here is more of a hack/workaround, and an inversion of the [dispose pattern](https://en.wikipedia.org/wiki/Dispose_pattern). In reality, `for..of` itself uses the dispose pattern internally.\r\n\r\nAlso, your example necessitates a number of allocations which could be expensive in a tight loop:\r\n- The \"iterable\" object created in the `using` function\r\n- Each iterator result object\r\n- The callback function passed to the `using` function\r\n- The environment record for the closure over `value`.\r\n\r\nThis is also hard to teach and explain, and harder to reason over when reviewing someone else's code.\r\n\r\nWith a native `using` statement, there would be no additional allocations over `for..of`:\r\n\r\n```js\r\nusing (value) {\r\n  console.log(value);\r\n}\r\n```\r\n\r\nEffectively becomes:\r\n\r\n```js\r\nconst _a = value;\r\ntry {\r\n  console.log(value);\r\n}\r\nfinally {\r\n  if (_a !== null && _a !== undefined) _a[Symbol.dispose]();\r\n}\r\n```\r\n\r\nThis is more efficient both memory and time wise."}}
{"actor":{"display_login":"rbuckton"}}