Eric
Eric

Reputation: 1678

How to consume async methods from the client perspective

So I'm taking a keen interest in the whole functional reactive paradigm, and trying to put some of these practices into place. But the one thing I'm still struggling with understanding is how to consume these asynchronous server-side calls on the front-end. So let's say your service layer results in an Observable<?> object, which will be called by your controller. Great. But now, how do you handle this async result from the client-side? Normally this is where you would block for the result, say from a Future<?> object, and then construct your result object and send it back to the calling client. But the whole point is to not block, so what do you do with your Observable now? Do you have to use web sockets to "push" the result down once it's available?

I hope this question makes sense. As long as the calls and result consumers exist on the server side, all of this makes sense. But in a web application, where the client expects results after calling the controller, I don't understand how to keep the async, reactive paradigm here. Any help is great appreciated in understanding this.

Upvotes: 4

Views: 280

Answers (1)

James World
James World

Reputation: 29806

Yes, you would use something like web sockets to "push" the result. This is a fundamental quality of the functional reactive paradigm - the client "reacts" to results being pushed, just like any implementation of the (gang of four) observer pattern.

There is a javascript implementation of rx from the original Microsoft team btw, which may be of interest. Find it here.

Upvotes: 1

Related Questions