Skip to content

Commit f991b19

Browse files
committed
WIP
1 parent 6ff1869 commit f991b19

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

cadence/async/event_loop.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
from asyncio import AbstractEventLoop
4+
from asyncio import Future
5+
import asyncio
6+
7+
class EventLoop(AbstractEventLoop):
8+
__running = False
9+
10+
def __init__(self):
11+
super().__init__()
12+
13+
def run_until_complete(self, future: Future):
14+
pass
15+
16+
def start(self):
17+
self.__running = True
18+
19+
def is_running(self):
20+
return self.__running
21+
22+
async def workflow():
23+
asyncio.set_event_loop(EventLoop())
24+
25+
task1 = asyncio.create_task(delay_print("Hello, world!", 1))
26+
task2 = asyncio.create_task(delay_print("Hello, world!", 1))
27+
await task1
28+
await task2
29+
30+
31+
async def delay_print(message, delay):
32+
await asyncio.sleep(delay)
33+
print(message)
34+
35+
36+
if __name__ == "__main__":
37+
print("Starting workflow")
38+
loop = asyncio.new_event_loop()
39+
loop.start()
40+
loop.run_until_complete(workflow())

0 commit comments

Comments
 (0)