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
feat: Iterable RPC calls. #47
Comments
Thank you for sharing the idea! Hum but yeah I think it makes more sense as an extension of this library because it seems the use case is uncommon (I think returning an array suffices the most use cases) and it's outside of JSON-RPC specs. |
Thanks for considering it.
I don't think the use case is uncommon - it is essentially just a stream which is obviously needed for a lot of things but it allows running multiple simultaneous streams inside the same RPC protocol. Perhaps my example was a bit basic there but a more concrete example would be returning a file stream which itself is iterable and hence would allow the file to converted back to a stream easily on the remote end. Here is a simple example of downloading a file from a server: // Remote
rpc.addTask("read-file", ({ path }) => {
return fs.createReadStream(path);
});
// Local
// (This could be simplified further using streaming iterables.)
const stream = fs.createWriteStream("file.txt");
for await (const value of rpc.runTask("read-file", { path: "/remote/file.txt" })) {
stream.write(value);
}
It would unfortunately have to fall under system extensions. Regardless I will make an extension that provides this functionality. |
Would you be interested in a PR for adding iterable RPC methods?
I have just been calling them tasks (Perhaps there is a better name?) but they are just build on top of the existing API and therefore I can see that it is questionable if it should be a part of this library or not.
This would look like the following:
The text was updated successfully, but these errors were encountered: