narupa.utilities.change_buffers module¶
Module providing utility classes used by the multiplayer service to create a shared key/value store between multiple clients.
-
class
narupa.utilities.change_buffers.
DictionaryChange
(updates: Optional[Mapping[str, Any]] = None, removals: Optional[Iterable[str]] = None)¶ Bases:
object
-
class
narupa.utilities.change_buffers.
DictionaryChangeBuffer
¶ Bases:
object
Tracks the latest values of keys that have changed between checks.
-
flush_changed_blocking
() → narupa.utilities.change_buffers.DictionaryChange¶ Wait until there are changes and then return them, clearing all tracked changes.
-
freeze
()¶ Freeze the buffer, ensuring that it cannot be updated with any more changes.
It will still be possible to flush changes one last time if there were any unflushed at the time of freezing.
-
subscribe_changes
(interval: float = 0) → Iterator[narupa.utilities.change_buffers.DictionaryChange]¶ Iterates over changes to the buffer. Waits at least :interval: seconds between each iteration.
-
update
(updates: Mapping[str, Any] = None, removals: Iterable[str] = None)¶ Update the known changes from a dictionary of keys that have changed to their new values or have been removed.
-
-
class
narupa.utilities.change_buffers.
DictionaryChangeMultiView
¶ Bases:
object
Provides a means to acquire multiple independent DictionaryChangeBuffers tracking a shared dictionary.
-
copy_content
() → Dict[str, Any]¶ Return a shallow copy of the dictionary at this instant.
-
create_view
() → Generator[narupa.utilities.change_buffers.DictionaryChangeBuffer, None, None]¶ Returns a new DictionaryChangeBuffer that tracks changes to the shared dictionary, starting with the initial values.
-
freeze
()¶ Prevent any further updates to the shared dictionary, ensuring that future views and subscriptions are frozen and provide a single update with the final values.
-
remove_view
(view: narupa.utilities.change_buffers.DictionaryChangeBuffer)¶ Freeze the given change buffer and stop providing updates to it.
-
subscribe_changes
(interval: float = 0) → Iterator[narupa.utilities.change_buffers.DictionaryChange]¶ Iterates over changes to the shared dictionary, starting with the initial values. Waits at least :interval: seconds between each iteration.
-
update
(updates: Mapping[str, Any] = None, removals: Iterable[str] = None)¶ Updates the shared dictionary with key values pairs from :updates: and key removals from :removals:.
-
-
exception
narupa.utilities.change_buffers.
ObjectFrozenError
¶ Bases:
Exception
Raised when an operation on an object cannot be performed because the object has been frozen.