mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 13:19:44 -06:00
* feat: snippets * feat: first couple paragraphs * feat: flesh out hatchet examples * fix: one more * feat: log view * fix: cleanup * feat: another section * fix: fmt * feat: debugging section * fix: proofread * fix: lint * chore: gen * fix: copilot * fix: copilot * feat: add blog post link * fix: feedback * chore: sdk ver * chore: gen * fix: ugh
53 lines
869 B
Python
53 lines
869 B
Python
# > Functions
|
|
import asyncio
|
|
import time
|
|
|
|
SLEEP_TIME = 3
|
|
|
|
|
|
async def blocking() -> None:
|
|
for i in range(SLEEP_TIME):
|
|
print("Blocking", i)
|
|
time.sleep(1)
|
|
|
|
|
|
async def non_blocking(task_id: str = "Non-blocking") -> None:
|
|
for i in range(SLEEP_TIME):
|
|
print(task_id, i)
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
|
|
|
|
# > Blocked
|
|
async def blocked() -> None:
|
|
loop = asyncio.get_event_loop()
|
|
|
|
await asyncio.gather(
|
|
*[
|
|
loop.create_task(blocking()),
|
|
loop.create_task(non_blocking()),
|
|
]
|
|
)
|
|
|
|
|
|
|
|
|
|
# > Unblocked
|
|
async def working() -> None:
|
|
loop = asyncio.get_event_loop()
|
|
|
|
await asyncio.gather(
|
|
*[
|
|
loop.create_task(non_blocking("A")),
|
|
loop.create_task(non_blocking("B")),
|
|
]
|
|
)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(blocked())
|
|
asyncio.run(working())
|