Skip to content

Commit

Permalink
Run response_listener task
Browse files Browse the repository at this point in the history
  • Loading branch information
marios8543 committed Oct 17, 2023
1 parent 07c8ddc commit 315b2f9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions backend/src/plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from asyncio import Task, create_task
from json import dumps, load, loads
from logging import getLogger
from os import path
Expand Down Expand Up @@ -31,12 +32,12 @@ def __init__(self, file: str, plugin_directory: str, plugin_path: str) -> None:
self.sandboxed_plugin = SandboxedPlugin(self.name, self.passive, self.flags, self.file, self.plugin_directory, self.plugin_path, self.version, self.author)
#TODO: Maybe somehow make LocalSocket not require on_new_message to make this more clear
self.socket = LocalSocket(self.sandboxed_plugin.on_new_message)
self.sandboxed_plugin.start(self.socket)
self.listener_task: Task[Any]

def __str__(self) -> str:
return self.name

async def response_listener(self):
async def _response_listener(self):
while True:
line = await self.socket.read_single_line()
if line != None:
Expand All @@ -52,4 +53,15 @@ async def execute_method(self, method_name: str, kwargs: Dict[Any, Any]):
await self.socket.write_single_line(dumps({ "method": method_name, "args": kwargs, "id": request.id }, ensure_ascii=False))
self.method_call_requests[request.id] = request

return await request.wait_for_result()
return await request.wait_for_result()

async def start(self):
self.sandboxed_plugin.start(self.socket)
self.listener_task = create_task(self._response_listener())

async def stop(self):
self.listener_task.cancel()
async def _(self: PluginWrapper):
await self.socket.write_single_line(dumps({ "stop": True }, ensure_ascii=False))
await self.socket.close_socket_connection()
create_task(_(self))

0 comments on commit 315b2f9

Please sign in to comment.