Skip to content

Instantly share code, notes, and snippets.

@bryaneaton
Created November 3, 2023 18:36
Show Gist options
  • Save bryaneaton/b4adb1d023c001a73c6319a3a70757d6 to your computer and use it in GitHub Desktop.
Save bryaneaton/b4adb1d023c001a73c6319a3a70757d6 to your computer and use it in GitHub Desktop.
Asyncio and Click
import asyncio
# Async operation definition remains the same
async def async_operation():
print("Starting async operation")
await asyncio.sleep(1)
print("Async operation completed")
# This is the main coroutine that will gather and run the async tasks
async def run_multiple_async_operations(count):
tasks = [async_operation() for _ in range(count)]
await asyncio.gather(*tasks) # Use gather to run tasks concurrently
# The click command calls the coroutine using asyncio.run
@actions.command(name="run_async")
@click.option('--count', default=1, help='Number of times to run the async operation.')
def run_async(count):
asyncio.run(run_multiple_async_operations(count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment