-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Context
Currently, check_session_values in Scripts/s4ap/persistance/ap_session_data_store.py uses a hybrid approach that supports both synchronous (legacy) and asynchronous (callback-based) calling patterns. This was intentionally kept as a transitional state while the testing environment is essentially production.
Related PR: #12
Discussion: #12 (comment)
Current State (Hybrid Approach)
The method signature currently is:
def check_session_values(
self,
host_name: str,
port: int,
seed_name: str,
player: str,
slot: int,
on_complete: Optional[Callable[[bool], None]] = None
) -> bool:Behavior:
- When
on_complete=None: Returns a boolean synchronously (legacy behavior, but unsafe with dialogs) - When
on_completeis provided: Invokes the callback with the result (correct async pattern)
Why this exists:
- Testing environment is essentially production
- Need stable behavior for current beta release
- Full refactoring deferred until after beta stabilizes
Desired End State (Fully Async)
1. Update check_session_values signature
Make on_complete required and remove the boolean return:
def check_session_values(
self,
host_name: str,
port: int,
seed_name: str,
player: str,
slot: int,
on_complete: Callable[[bool], None] # No longer optional
) -> None: # No longer returns bool2. Ensure all dialog paths invoke the callback
All branches must call on_complete(True) or on_complete(False):
_ok_chosen: Callon_complete(True)_cancel_chosen: Callon_complete(False)- No dialog (None guard): Call
on_complete(False)immediately - Settings match: Call
on_complete(True)immediately
3. Refactor caller in auto_parse_json.py
The caller currently uses:
if data_store.check_session_values(host_name, port, seed_name, player, slot):
# continue processingThis needs to be refactored to:
def _on_session_check_complete(success: bool):
if not success:
cancel = True
return
# Continue with subsequent processing...
data_store.check_session_values(
host_name, port, seed_name, player, slot,
on_complete=_on_session_check_complete
)Migration Checklist
- Remove
Optionalfromon_completeparameter type - Change return type from
booltoNone - Remove all
return True/return Falsestatements in the function body - Ensure all code paths invoke
on_complete(bool) - Refactor caller in
auto_parse_json.pyto use callback pattern - Remove legacy synchronous code paths and deprecation warnings
- Test thoroughly in non-production environment
Why This Matters
The Sims 4 runtime does not support safe blocking on UI dialog interactions. Using blocking synchronization primitives (like threading.Event, Future.result(), etc.) will freeze the game loop. The callback-based pattern is the only safe way to handle async dialog results.
Timeline
To be addressed after the current beta release is stable and a proper testing environment is available.