Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support nested methods and event emitters #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gmaclennan
Copy link
Member

This allows you to call a nested method on the server e.g.
client.myMethod().otherMethod()

This is only a proof-of-concept and will not yet work. Implementing this probably requires support for Weak References and Finalizers that were added in Node v14.6.0+. They are needed because the server needs to keep a reference to the object returned by client.myMethod() for as long as the client does. E.g.

const subClient = client.myMethod()
const result = await subClient.otherMethod()

We need a WeakRef to garbage collect subClient on the server when it is garbage collected on the client. Otherwise memory will grow on the server since we need to keep around any returned values forever.

It might be too difficult to implement this bug-free, it's probably better to avoid this pattern for an API that is going to be called over RPC.

This allows you to call a nested method on the server e.g.
client.myMethod().otherMethod()
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.

1 participant