-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dff0d7
commit 537556f
Showing
14 changed files
with
433 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Callable, Coroutine | ||
|
||
from .entities.decorator import TemplateDecorator | ||
from .entities.subscriber import Subscriber | ||
from .utils import ArgumentPackage | ||
from .handler import await_exec_target | ||
|
||
|
||
class Depend(TemplateDecorator): | ||
target: Subscriber | ||
|
||
def __init__(self, callable_func: Callable): | ||
super().__init__(keep=False) | ||
self.target = Subscriber(callable_func) | ||
|
||
def supply(self, target_argument: ArgumentPackage) -> Coroutine: | ||
coro = await_exec_target(self.target, target_argument.value) | ||
return coro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ class PropagationCancelled(Exception): | |
pass | ||
|
||
|
||
class ExecutionStop(Exception): | ||
class ParsingStop(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
import asyncio | ||
from arclet.letoderea import EventSystem | ||
from arclet.letoderea.entities.event import TemplateEvent | ||
from arclet.letoderea.breakpoint.stepout import StepOut | ||
from arclet.letoderea.breakpoint import Breakpoint | ||
|
||
loop = asyncio.get_event_loop() | ||
test_stack = [0] | ||
es = EventSystem(loop=loop) | ||
break_point = Breakpoint(event_system=es) | ||
|
||
|
||
class TestStepOut(StepOut): | ||
|
||
@staticmethod | ||
def handler(msg: str): | ||
if msg == "continue!": | ||
print(msg) | ||
return msg | ||
|
||
|
||
class ExampleEvent(TemplateEvent): | ||
type: str = "ExampleEvent" | ||
msg: str | ||
|
||
def get_params(self): | ||
return self.param_export( | ||
str=self.msg | ||
) | ||
|
||
|
||
@es.register(ExampleEvent) | ||
async def test(m: str): | ||
if m == 'hello': | ||
print("wait for msg:'continue!' ") | ||
await break_point(TestStepOut(ExampleEvent)) | ||
print(m) | ||
|
||
|
||
a = ExampleEvent() | ||
a.msg = "hello" | ||
b = ExampleEvent() | ||
b.msg = "continue!" | ||
|
||
|
||
async def main(): | ||
for i in range(0, 4): | ||
if i % 2 == 0: | ||
print('>>> event posted with msg: "hello"') | ||
es.event_spread(a) | ||
else: | ||
print('>>> event posted with msg: "continue!"') | ||
es.event_spread(b) | ||
await asyncio.sleep(1) | ||
|
||
|
||
loop.run_until_complete(main()) | ||
import asyncio | ||
from arclet.letoderea import EventSystem | ||
from arclet.letoderea.entities.event import TemplateEvent | ||
from arclet.letoderea.breakpoint.stepout import StepOut | ||
from arclet.letoderea.breakpoint import Breakpoint | ||
|
||
loop = asyncio.get_event_loop() | ||
test_stack = [0] | ||
es = EventSystem(loop=loop) | ||
break_point = Breakpoint(event_system=es) | ||
|
||
|
||
class TestStepOut(StepOut): | ||
|
||
@staticmethod | ||
def handler(msg: str): | ||
if msg == "continue!": | ||
print(msg) | ||
return msg | ||
|
||
|
||
class ExampleEvent(TemplateEvent): | ||
type: str = "ExampleEvent" | ||
msg: str | ||
|
||
def get_params(self): | ||
return self.param_export( | ||
str=self.msg | ||
) | ||
|
||
|
||
@es.register(ExampleEvent) | ||
async def test(m: str): | ||
if m == 'hello': | ||
print("wait for msg:'continue!' ") | ||
await break_point(TestStepOut(ExampleEvent)) | ||
print(m) | ||
|
||
|
||
a = ExampleEvent() | ||
a.msg = "hello" | ||
b = ExampleEvent() | ||
b.msg = "continue!" | ||
|
||
|
||
async def main(): | ||
for i in range(0, 4): | ||
if i % 2 == 0: | ||
print('>>> event posted with msg: "hello"') | ||
es.event_spread(a) | ||
else: | ||
print('>>> event posted with msg: "continue!"') | ||
es.event_spread(b) | ||
await asyncio.sleep(1) | ||
|
||
|
||
loop.run_until_complete(main()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,49 @@ | ||
from datetime import datetime | ||
from arclet.letoderea.entities.condition import TemplateCondition | ||
import asyncio | ||
from arclet.letoderea import EventSystem | ||
from arclet.letoderea.entities.event import TemplateEvent | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
test_stack = [0] | ||
es = EventSystem(loop=loop) | ||
|
||
|
||
class TestCondition(TemplateCondition): | ||
|
||
def __init__(self, hour, minute): | ||
self.hour = hour | ||
self.minute = minute | ||
|
||
def judge(self, *args, **kwargs) -> bool: | ||
now = datetime.now() | ||
return now > datetime(year=now.year, month=now.month, day=now.day, hour=self.hour, minute=self.minute) | ||
|
||
|
||
class ExampleEvent(TemplateEvent): | ||
type: str = "ExampleEvent" | ||
msg: int | ||
|
||
def get_params(self): | ||
return self.param_export( | ||
int=self.msg | ||
) | ||
|
||
|
||
@es.register(ExampleEvent, conditions=[TestCondition(23, 30)]) | ||
async def test(a: str = "hello"): | ||
for i in range(5): | ||
await asyncio.sleep(0.1) | ||
print(a) | ||
loop.stop() | ||
|
||
|
||
b = ExampleEvent() | ||
b.msg = 1 | ||
es.event_spread(b) | ||
loop.run_forever() | ||
|
||
from datetime import datetime | ||
from arclet.letoderea.entities.condition import TemplateCondition | ||
import asyncio | ||
from arclet.letoderea import EventSystem | ||
from arclet.letoderea.entities.event import TemplateEvent | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
test_stack = [0] | ||
es = EventSystem(loop=loop) | ||
|
||
|
||
class TestCondition(TemplateCondition): | ||
|
||
def __init__(self, hour, minute): | ||
self.hour = hour | ||
self.minute = minute | ||
|
||
def judge(self, *args, **kwargs) -> bool: | ||
now = datetime.now() | ||
return now > datetime(year=now.year, month=now.month, day=now.day, hour=self.hour, minute=self.minute) | ||
|
||
|
||
class ExampleEvent(TemplateEvent): | ||
type: str = "ExampleEvent" | ||
msg: int | ||
|
||
def get_params(self): | ||
return self.param_export( | ||
int=self.msg | ||
) | ||
|
||
|
||
@es.register(ExampleEvent, conditions=[TestCondition(22, 30)]) | ||
async def test(a: str = "hello"): | ||
print(a) | ||
|
||
|
||
b = ExampleEvent() | ||
b.msg = 1 | ||
|
||
|
||
async def main(): | ||
for i in range(5): | ||
await asyncio.sleep(0.1) | ||
es.event_spread(b) | ||
|
||
loop.run_until_complete(main()) | ||
|
Oops, something went wrong.