{"action":"created","issue":{"url":"https://api.github.com/repos/nikomatsakis/rayon/issues/71","repository_url":"https://api.github.com/repos/nikomatsakis/rayon","labels_url":"https://api.github.com/repos/nikomatsakis/rayon/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/nikomatsakis/rayon/issues/71/comments","events_url":"https://api.github.com/repos/nikomatsakis/rayon/issues/71/events","html_url":"https://github.com/nikomatsakis/rayon/pull/71","id":144196241,"number":71,"title":"introduce explicit scope API; cleanup unwinding","user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-03-29T08:43:17Z","updated_at":"2016-10-14T14:23:20Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nikomatsakis/rayon/pulls/71","html_url":"https://github.com/nikomatsakis/rayon/pull/71","diff_url":"https://github.com/nikomatsakis/rayon/pull/71.diff","patch_url":"https://github.com/nikomatsakis/rayon/pull/71.patch"},"body":"This PR introduces an explicit scope API to complement `join`:\r\n\r\n```rust\r\nscope(|scope| {\r\n    for i in 0 .. 10 {\r\n        scope.spawn(|scope| {\r\n            // the parameter `scope` can be used to spawn yet more work within the same overall scope\r\n            process(scope, i);\r\n        })\r\n})\r\n```\r\n\r\nIn general, `join` is to be preferred, both because it is easier to use (you don't have to define the \"scope\") and because it leverages stack allocation instead of heap allocation. However, there are some cases where `join` is not a good fit. For example, if you are processing a worklist of items, where each item may yield more items, scope can be very convenient:\r\n\r\n```rust\r\nscope(|scope| {\r\n    for item in initial_worklist {\r\n        scope.spawn(|scope| process(scope, item));\r\n    }\r\n})\r\n\r\nfn process<'scope>(scope: &Scope<'scope>, item: Item) {\r\n    for item in item.dependent_items {\r\n        scope.spawn(|scope| process(scope, item));\r\n    }\r\n}\r\n```\r\n\r\nNote that this is basically a flat-map, but the number of flat-maps being performed depends on the shape of the data. \r\n\r\n~~Anyway, this is a bit of WIP: there aren't many tests and I suspect that the code is buggy in more than a couple of ways. But I thought I'd toss it up and see what people thought.~~\r\n\r\nWork items to address:\r\n\r\n- [x] leaks\r\n- [ ] tests for panic handling\r\n- [ ] blocked jobs help each other out"},"comment":{"url":"https://api.github.com/repos/nikomatsakis/rayon/issues/comments/253814532","html_url":"https://github.com/nikomatsakis/rayon/pull/71#issuecomment-253814532","issue_url":"https://api.github.com/repos/nikomatsakis/rayon/issues/71","id":253814532,"user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"created_at":"2016-10-14T14:23:19Z","updated_at":"2016-10-14T14:23:19Z","body":"Bah. The travis failure is because my home-rolled leak-check is racy. Have to think about the best fix for that."}}
{"actor":{"display_login":"nikomatsakis"}}