WIP: Support nested methods and event emitters #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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.