LearnNewsExamplesServices
Frontmatter
id8147
titleEnhancement: Async Remote Method Registration and Robust Worker Checking
stateClosed
labels
enhancementaicore
assigneestobiu
createdAtDec 19, 2025, 10:07 PM
updatedAtDec 19, 2025, 10:27 PM
githubUrlhttps://github.com/neomjs/neo/issues/8147
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 19, 2025, 10:27 PM

Enhancement: Async Remote Method Registration and Robust Worker Checking

Closed v11.17.0 enhancementaicore
tobiu
tobiu commented on Dec 19, 2025, 10:07 PM

This PR introduces a robust, asynchronous mechanism for registering remote methods across workers, replacing the previous "fire-and-forget" approach with a deterministic promise-based flow. It also includes critical fixes for main thread synchronization and addon registration.

Key Changes:

  1. Async Remote Registration (core.Base):

    • Renamed sendRemotes to promiseRemotes.
    • promiseRemotes now returns a Promise that resolves only when the target worker acknowledges the registration.
    • initRemote and initAsync are now fully async and await this process.
    • Added remotesReady() method and #remotesReadyPromise to allow external callers (like Neo.Main) to await full initialization.
  2. Robust Worker Checking (hasWorker):

    • Implemented hasWorker(name) in Neo.worker.Base and Neo.worker.Manager.
    • This method checks Neo.config (e.g., useCanvasWorker, useServiceWorker) or the active worker list to determine if a target worker actually exists.
    • promiseRemotes now uses origin.hasWorker() to prevent sending messages to non-existent optional workers (like task or canvas), fixing runtime errors when these are disabled.
  3. Main Thread Synchronization (Neo.Main & Neo.worker.Manager):

    • Neo.Main: onDomContentLoaded now explicitly awaits remotesReady() for all registered addons and the main instance itself. Removed the arbitrary timeout(20) race-condition workaround.
    • Neo.worker.Manager: Updated onWorkerConstructed to check for activeWorkers + 1. The + 1 accounts for the main thread itself, ensuring loadApplication is only triggered when all threads (workers + main) are ready.
  4. Addon Registration Fix (Neo.Main):

    • Fixed a race condition in registerAddon. If called multiple times (e.g., via remote method access) before completion, it could incorrectly overwrite the singleton instance in the namespace with the class constructor. The fix ensures Neo.applyToGlobalNs(addon) is only called when a new instance is actually created.
  5. Service Worker Support:

    • Added service worker support to hasWorker checks, honoring Neo.config.useServiceWorker.

Goal: Eliminate race conditions during application startup and ensure that all remote methods are guaranteed to be registered before the application logic proceeds.

tobiu added the enhancement label on Dec 19, 2025, 10:07 PM
tobiu added the ai label on Dec 19, 2025, 10:07 PM
tobiu added the core label on Dec 19, 2025, 10:07 PM
tobiu assigned to @tobiu on Dec 19, 2025, 10:07 PM
tobiu referenced in commit 252196e - "Enhancement: Async Remote Method Registration and Robust Worker Checking #8147" on Dec 19, 2025, 10:20 PM
tobiu closed this issue on Dec 19, 2025, 10:27 PM
tobiu cross-referenced by #8338 on Jan 5, 2026, 8:30 PM