Skip to content

Fix hang on empty {} blocks in generators and async functions - #76

Open
schloerke wants to merge 2 commits into
r-lib:mainfrom
schloerke:schloerke/async_generator-hang-bug
Open

schloerke wants to merge 2 commits into
r-lib:mainfrom
schloerke:schloerke/async_generator-hang-bug

Conversation

@schloerke

Copy link
Copy Markdown

Fixes #75. An empty {} block in a generator or async function body made the generator loop forever. Examples include generator(function() {}), async(function() {}), and generator(function() { yield(1); {} }).

There were two causes, both in block_states(). An empty function body produced no states, so the main repeat { switch(...) } loop never exited. An empty nested block got spliced into its parent and added nothing, which dropped the final state, so the generator never finished. Both cases now treat {} as NULL, which matches plain R, where function() {} returns NULL.

The tests were written first and fail without the fix. They use a small with_time_limit() helper so that a hang fails the test instead of freezing the suite.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty {} block makes generators and async functions hang

1 participant