eureca.io icon indicating copy to clipboard operation
eureca.io copied to clipboard

Multiple Async callbacks

Open the-duke opened this issue 9 years ago • 2 comments

Hello, I like your rpc framework on top top primus.io. Awesome work! For now, I used in my project dnode rpc with shoe on top of sock.js. I would like to migrate to eureca.io but I need that a server can responed multiple chunks to the client before the async "context.return()" method is called. This would be a kind of streaming, like in dnode or grpc. I know, for this purpose, it is possible do define a stub on the client side, which the server can callback for progress information, but I don't like the coding overhead to associate these client and server functions to each other. A "context.progress()" function would be really nice! On the client side a proxy stub call would callback a progress function passed as third argument to the promise: proxy.asyncServerHello().then( function(success) {}, function(error){}, function(progress){});

Best regards

Thomas

the-duke avatar Jul 08 '16 11:07 the-duke

Hello @the-duke and welcome to eureca.io :) Actually I was thinking of an implementation of such solution, but I don't like to add a third callback to the promise, since it's not a standard. there are many possible solutions, but this need reflexion to make the best solution which cover most of use cases.

one of those could be something like

proxy.asyncServerHello().then( function(success, finished) {}, function(error){}

when the "finished" argument is true, it means that the server called context.return() otherwise it'll mean that the server called .progress()

this is still not compliant with Promises syntax but it's a better solution imo.

another approach could be something like :

proxy.asyncServerHello().progress(function(value) {}).then( function(success) {}, function(error){}

still trying to figure out the best approach

alaa-eddine avatar Jul 08 '16 12:07 alaa-eddine

Thank you for your fast reply an thinking about implementation. I use a lot of dojo toolkit and there the progress callback is passed as third argument. dojo/promise/Promise

But, while dojo might be not very common, i like your first solution with the finished argument.

Thank you a lot, i hope implementation is not too hard work for you.

the-duke avatar Jul 08 '16 13:07 the-duke