-
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#338 introduce outbox; update elements during initialization, not whe…
…n leaving container
- Loading branch information
1 parent
216d315
commit 3c00a86
Showing
15 changed files
with
63 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import asyncio | ||
from collections import deque | ||
from typing import TYPE_CHECKING, Any, Deque, Literal, Tuple | ||
|
||
from . import globals | ||
|
||
if TYPE_CHECKING: | ||
from .element import Element | ||
ClientId = int | ||
MessageType = Literal['update', 'run_method', 'run_javascript', 'open', 'notify'] | ||
MessageGroup = Tuple[ClientId, MessageType, Any] | ||
|
||
queue: Deque['MessageGroup'] = deque() | ||
|
||
|
||
def enqueue_update(element: 'Element') -> None: | ||
if queue: | ||
client_id, message_type, argument = queue[-1] | ||
if client_id == element.client.id and message_type == 'update': | ||
elements: Deque[Element] = argument | ||
elements.append(element) | ||
return | ||
queue.append((element.client.id, 'update', deque([element]))) | ||
|
||
|
||
def enqueue_message(message_type: 'MessageType', data: Any, client_id: 'ClientId') -> None: | ||
queue.append((client_id, message_type, data)) | ||
|
||
|
||
async def loop() -> None: | ||
while True: | ||
while queue: | ||
client_id, message_type, data = queue.popleft() | ||
if message_type == 'update': | ||
messages: Deque[Element] = data | ||
data = {'elements': {e.id: e.to_dict() for e in messages}} | ||
await globals.sio.emit(message_type, data, room=client_id) | ||
await asyncio.sleep(0.01) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters