nanover.utilities.change_buffers module

Module providing utility classes used by the multiplayer service to create a shared key/value store between multiple clients.

class nanover.utilities.change_buffers.DictionaryChange(updates: Mapping[str, Any] | None = None, removals: Iterable[str] | None = None)

Bases: object

removals: Iterable[str]
updates: Mapping[str, Any]
class nanover.utilities.change_buffers.DictionaryChangeBuffer

Bases: object

Tracks the latest values of keys that have changed between checks.

flush_changed_blocking() 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[DictionaryChange]

Iterates over changes to the buffer. Waits at least :interval: seconds between each iteration.

update(updates: Mapping[str, Any] | None = None, removals: Iterable[str] | None = None)

Update the known changes from a dictionary of keys that have changed to their new values or have been removed.

class nanover.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[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: DictionaryChangeBuffer)

Freeze the given change buffer and stop providing updates to it.

subscribe_changes(interval: float = 0) Iterator[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 = None, removals: Iterable[str] | None = None)

Updates the shared dictionary with key values pairs from :updates: and key removals from :removals:.

exception nanover.utilities.change_buffers.ObjectFrozenError

Bases: Exception

Raised when an operation on an object cannot be performed because the object has been frozen.