Daemon now must be async (more consistent)

develop
Jef Roosens 2020-08-27 13:06:22 +02:00
parent f6f081bfba
commit e7637a1bce
3 changed files with 12 additions and 4 deletions

View File

@ -1,3 +1,7 @@
## Unreleased
### Added
- Daemons can now accept an interval value, removing the need for a manual while True loop
## v0.1 (2020/08/26) ## v0.1 (2020/08/26)
### Added ### Added

View File

@ -122,7 +122,7 @@ class Daemon(Simple):
if interval > 0: if interval > 0:
async def loop(self, *args, **kwargs): async def loop(self, *args, **kwargs):
while True: while True:
func(self, *args, **kwargs) await func(self, *args, **kwargs)
await asyncio.sleep(interval) await asyncio.sleep(interval)

View File

@ -1,4 +1,7 @@
# =====IMPORTS===== # =====IMPORTS=====
# Third-party imports
import pytest
# Own imports # Own imports
from frank import default, command, daemon from frank import default, command, daemon
@ -27,7 +30,7 @@ class TestDecorators:
return 'daemon' return 'daemon'
@daemon() @daemon()
def daemon_dec(self): async def daemon_dec(self):
return self.daemon_no_dec() return self.daemon_no_dec()
def test_default(self): def test_default(self):
@ -36,5 +39,6 @@ class TestDecorators:
def test_command(self): def test_command(self):
assert self.command_no_dec() == self.command_dec() assert self.command_no_dec() == self.command_dec()
def test_daemon(self): @pytest.mark.asyncio
assert self.daemon_no_dec() == self.daemon_dec() async def test_daemon(self):
assert self.daemon_no_dec() == await self.daemon_dec()