Skip to content

docs: add two-way communication guidance#694

Open
KirtiRamchandani wants to merge 1 commit into
GoogleChromeLabs:mainfrom
KirtiRamchandani:docs/two-way-communication-guidance
Open

docs: add two-way communication guidance#694
KirtiRamchandani wants to merge 1 commit into
GoogleChromeLabs:mainfrom
KirtiRamchandani:docs/two-way-communication-guidance

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

Problem

#672 asks for explicit documentation around using Comlink when both sides of a channel need to call into each other.

Root cause

The README documents callbacks and one-direction worker APIs, but does not spell out how wrap() and expose() compose when each side has its own API. That can make users infer an unsupported limitation or try to overload one endpoint with multiple objects.

Solution

Add a Two-way communication section that:

  • explains that wrap() consumes the other side while expose() publishes the current side,
  • shows a main-thread/worker example where both sides expose APIs,
  • points callback-style use cases to Comlink.proxy(), and
  • suggests MessageChannel/createEndpoint() for independent APIs.

Tests run

  • npm exec --yes prettier@2.8.3 -- --check README.md
  • git diff --check

Fixes #672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicitly mention in the document of Comlink's limitation on bidirectional communication between main thread and worker

1 participant