[WIP] Added scheduler

This commit is contained in:
2023-04-16 21:46:17 +02:00
parent 39ca803d36
commit aabbfeaa92
51 changed files with 572 additions and 71 deletions

View File

@@ -0,0 +1,36 @@
import time
import unittest
from datetime import datetime
from cpl_core.console import Console
from cpl_reactive_extensions.scheduler.async_scheduler import async_scheduler
from cpl_reactive_extensions.timer import Timer
class SchedulerTestCase(unittest.TestCase):
def setUp(self):
pass
def test_timer(self):
count = 0
def task():
nonlocal count
Console.write_line(datetime.now(), "Hello world")
count += 1
timer = Timer(100, task)
time.sleep(0.25)
self.assertEqual(count, 2)
timer.clear()
def test_schedule(self):
count = 0
def task():
nonlocal count
Console.write_line(datetime.now(), "Hello world")
count += 1
async_scheduler.schedule(task, 100)
time.sleep(2)