{"action":"created","issue":{"url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/28","repository_url":"https://api.github.com/repos/observablehq/notebook-stdlib","labels_url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/28/comments","events_url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/28/events","html_url":"https://github.com/observablehq/notebook-stdlib/pull/28","id":314130476,"number":28,"title":"Add Generators.{dispose,worker}.","user":{"login":"mbostock","id":230541,"avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-04-13T14:30:59Z","updated_at":"2018-04-13T20:24:32Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/observablehq/notebook-stdlib/pulls/28","html_url":"https://github.com/observablehq/notebook-stdlib/pull/28","diff_url":"https://github.com/observablehq/notebook-stdlib/pull/28.diff","patch_url":"https://github.com/observablehq/notebook-stdlib/pull/28.patch"},"body":"These methods make it easier to clean up resources that need explicit disposal, such as workers and GPU-backed tensors. For example, a dedicated web worker:\r\n\r\n```js\r\nworker = Generators.worker(`\r\nonmessage = function ({data}) {\r\n  postMessage({echo: data});\r\n};\r\n`)\r\n```\r\n\r\nA tensor:\r\n\r\n```js\r\nx = Generators.dispose(tf.tensor2d([[0.0, 2.0], [4.0, 6.0]]), x => x.dispose())\r\n```"},"comment":{"url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/comments/381251443","html_url":"https://github.com/observablehq/notebook-stdlib/pull/28#issuecomment-381251443","issue_url":"https://api.github.com/repos/observablehq/notebook-stdlib/issues/28","id":381251443,"user":{"login":"nsthorat","id":1100749,"avatar_url":"https://avatars0.githubusercontent.com/u/1100749?v=4","gravatar_id":"","url":"https://api.github.com/users/nsthorat","html_url":"https://github.com/nsthorat","followers_url":"https://api.github.com/users/nsthorat/followers","following_url":"https://api.github.com/users/nsthorat/following{/other_user}","gists_url":"https://api.github.com/users/nsthorat/gists{/gist_id}","starred_url":"https://api.github.com/users/nsthorat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsthorat/subscriptions","organizations_url":"https://api.github.com/users/nsthorat/orgs","repos_url":"https://api.github.com/users/nsthorat/repos","events_url":"https://api.github.com/users/nsthorat/events{/privacy}","received_events_url":"https://api.github.com/users/nsthorat/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T20:24:32Z","updated_at":"2018-04-13T20:24:32Z","author_association":"NONE","body":"I just saw @tmcw comment with `const {tensor2d} = disposable(tf.tensor2d);`.\r\n\r\nThe only issue with this is that usually the tensor you're returning is the output of some mathematical operation, which means we'd have to hijack all of our operations to make them return generators (see the snippet I just linked above).\r\n\r\nI think generally speaking, the last code snippet I posted above is what a common cell will look like."}}
{"actor":{"display_login":"nsthorat"}}