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

Multiple function return values at different times #158

Open
leumasme opened this issue Feb 15, 2023 · 1 comment
Open

Multiple function return values at different times #158

leumasme opened this issue Feb 15, 2023 · 1 comment

Comments

@leumasme
Copy link

I looked through the documentation for a bit, but couldn't spot anything that would allow for returning multiple results at different times.
Example usecases for this would be a Node Script that starts multiple async jobs (like starting multiple web requests) and would like to return the result of each job as soon as it is done, without having to wait for each of them to complete.
Example implemententions on the JS side could look like an (async) generator function or a callback that can be called multiple times.
What the C# side of the implementation for the above methods could look like isnt clear to me.
The C# call could possibly provide one (or multiple!?) methods that would be called upon a callback/result.

It's perfectly reasonable if you declare this to be utterly out of scope - in this case, does anyone reading this happen to know of alternative libraries which provide such funcionality?
Thank you for your time either way.

@JeremyTCD
Copy link
Member

JeremyTCD commented Feb 15, 2023

Unfortunately this library doesn't support the use case you've described. In general it does not support bidirectionality - there's no way to register a callback on the dotnet side and invoke it from Node.js at arbitrary times.

This is because the underlying mechanism for inter-process communication is plain HTTP. An invocation of JS in Node.js is just a vanilla HTTP request - a request from .Net gets a single response from Node.js.

There've been requests for bidirectional mechanisms like websockets, which would allow for your use case, but they have not been implemented.

The only alternative for interop with Node.js that I'm aware of is this fork of Edge.js. It has limitations though, some are explained here.

Alternatively if you are able to run pure JS (no Node.js dependencies), you can use Microsoft's JS interop library.

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

No branches or pull requests

2 participants