Skip to content
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

refactor: refactor CLI to properly await async logic via a synchronous Click command #136

Merged
merged 3 commits into from
Jan 17, 2025

Conversation

filipchristiansen
Copy link
Collaborator

Summary

This PR fixes thecoroutine 'main' was never awaited RuntimeWarning by introducing a synchronous Click command (main) that wraps an async function (_async_main) with asyncio.run(). This approach ensures that Click’s command decorators see a normal sync function, while the actual logic runs asynchronously (and is properly awaited).

Key Changes

  • Added _async_main(...) function for the actual async logic.
  • Updated the Click-decorated main(...) to be synchronous, which calls _async_main(...) via asyncio.run().
  • Removed the previous direct async def usage under Click’s command decorator.

Benefits

  • No more RuntimeWarning about un-awaited coroutines.
  • Cleaner separation of concerns between sync CLI handling and async operations.

May be related to #125.

- Change main() to a synchronous Click command
- Introduce _async_main() for async ingest logic
- Use asyncio.run(...) to properly await the async function
@cyclotruc cyclotruc merged commit 71b1167 into main Jan 17, 2025
8 checks passed
@cyclotruc cyclotruc deleted the refactor/cli-async-await branch January 17, 2025 16:10
RyanL2004 pushed a commit to RyanL2004/gitingest that referenced this pull request Jan 18, 2025
…ruc#136)

- Change main() to a synchronous Click command
- Introduce _async_main() for async ingest logic
- Use asyncio.run(...) to properly await the async function
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.

2 participants