Skip to content

Support async for and async with constructs using macros #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025

Conversation

chrisrink10
Copy link
Member

Fixes #1179
Fixes #1181

@ikappaki
Copy link
Contributor

Hi @chrisrink10,

Both definitions look good. I've been using the following for async for, which seems simpler than using a loop. Is there a catch perhaps somewhere, in terms of coverage, expression or performance using a context manager?

(defmacro forasync
  [[var value] & body]
  `(let [~var ~value]
    (~'await (.__aenter__ ~var))
    (try
      ~@body
      (finally
        (~'await (.__aexit__ ~var nil nil nil))))))

Thanks

@chrisrink10
Copy link
Member Author

Both definitions look good. I've been using the following for async for, which seems simpler than using a loop. Is there a catch perhaps somewhere, in terms of coverage, expression or performance using a context manager?

I thought you wanted to have the async for loop?

@ikappaki
Copy link
Contributor

Both definitions look good. I've been using the following for async for, which seems simpler than using a loop. Is there a catch perhaps somewhere, in terms of coverage, expression or performance using a context manager?

I thought you wanted to have the async for loop?

Sorry, yes you're right, please ignore the above, that was a trivial async with impl.

@chrisrink10 chrisrink10 force-pushed the feature/async-macros branch from 97a1a98 to fd8e868 Compare April 11, 2025 01:20
@chrisrink10 chrisrink10 marked this pull request as ready for review April 11, 2025 01:21
@chrisrink10 chrisrink10 merged commit 88cfb0b into main Apr 11, 2025
12 checks passed
@chrisrink10 chrisrink10 deleted the feature/async-macros branch April 11, 2025 01:38
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.

Support for async iterators in seq functions Support for async with
2 participants