Daemon now must be async (more consistent)
parent
f6f081bfba
commit
e7637a1bce
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Reference in New Issue