handle message while stdin is not closed
This commit is contained in:
@@ -4,31 +4,37 @@ from typing import Callable
|
||||
from .Note import Note
|
||||
|
||||
async def wait_until(dt):
|
||||
# sleep until the specified datetime
|
||||
now = datetime.datetime.now()
|
||||
await asyncio.sleep((dt - now).total_seconds())
|
||||
# sleep until the specified datetime
|
||||
now = datetime.datetime.now()
|
||||
await asyncio.sleep((dt - now).total_seconds())
|
||||
|
||||
async def run_at(dt, coro):
|
||||
await wait_until(dt)
|
||||
return await coro
|
||||
await wait_until(dt)
|
||||
return await coro
|
||||
|
||||
class Partition:
|
||||
|
||||
def __init__(self, name:str, notes:list[Note]) -> None:
|
||||
|
||||
self.__name = name
|
||||
self.__notes = notes
|
||||
|
||||
async def play(self, output_lambda:Callable[[object], None]):
|
||||
now = datetime.datetime.now()
|
||||
tasks_to_wait = []
|
||||
for note in self.__notes:
|
||||
tasks_to_wait.append(
|
||||
asyncio.create_task(
|
||||
run_at(
|
||||
now + datetime.timedelta(milliseconds= note.get_start_time()),
|
||||
output_lambda(note.get_data())
|
||||
)
|
||||
)
|
||||
)
|
||||
await asyncio.wait(tasks_to_wait)
|
||||
def __init__(self, name:str, notes:list[Note]) -> None:
|
||||
|
||||
self.__name = name
|
||||
self.__notes = notes
|
||||
|
||||
async def play(self, output_lambda:Callable[[object], None]):
|
||||
now = datetime.datetime.now()
|
||||
tasks_to_wait = []
|
||||
for note in self.__notes:
|
||||
tasks_to_wait.append(
|
||||
asyncio.create_task(
|
||||
run_at(
|
||||
now + datetime.timedelta(milliseconds= note.get_start_time()),
|
||||
output_lambda(note.get_data())
|
||||
)
|
||||
)
|
||||
)
|
||||
await asyncio.wait(tasks_to_wait)
|
||||
def __repr__(self):
|
||||
r = f"{self.__name}\n"
|
||||
for i in self.__notes:
|
||||
r += f"{i.get_data()}\n"
|
||||
return r
|
||||
|
||||
|
||||
Reference in New Issue
Block a user