The short answer
Shouldn't be a problem. Reactive programming isn't concerned with data formats or publishers at the level of a network. It's entirely possible to have only a small bit of functionality be reactive without impacting the rest of your codebase at all.
JavaScript and Java both let you switch between reactive and imperative styles with minimal fuss.
Just like it doesn't matter what language a server or a client is running so long as they can both read and send well-formed messages. Reactive libraries are generally entirely self-contained.
The longer answer
From a client's point of view, what your server is doing can be abstracted in many ways. What's simplest/best has a lot more to do with your networking libraries than the server. An angular app (for example) can treat any and all network traffic as streams using Angular's HttpClient. It doesn't matter what the server is doing, nor how it sends packets. Angular can pass them on as streams.
Even if it's not built-in, it should be relatively easy to layer reactive libraries on top of whatever else exists.
Subjects are the building block that let you seamlessly switch between reactive/functional styles and imperative styles of programming.
However you're receiving data currently, you can create a subject and use its .next
to pass that data into a stream.
public payloadData: Subject;
function processData(payload){
this.payloadData.next(payload);
}
Then you're on your way. You can build out your reactive framework from there.
/***
* An observable, that (once subscribed) begins to keep a timestamped array of all
* values emitted by payloadData.
*
* TODO: Remove stale data and write it to disk.
***/
function accumulateDataHistory(): Observable {
return this.payloadData.pipe(
timestamp(),
scan((acc, curr) => ([...acc, curr]), []),
shareReplay(1)
)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…