I have a program written where the client side is in JavaScript (React) and the server side is written in Python using Flask. I want the client side to refresh data every 30 seconds but I want the server side to refresh at different paces (i want Route A to refresh every 30 seconds, Route B to refresh every 60 seconds) By Route I am referring to Python-Flask Routes.
So far in my client side (as far as this refreshing code goes) I have
refreshData() {
request.get("/cData")
.end((err,res) => {
if (err) {
console.log("error cdata request: " + err);
return;
}
this.setState({cTimes: res.body});
});
request.get("/mData")
.end((err,res) => {
if (err) {
console.log("error mdata request: " + err);
return;
}
this.setState({mTimes: res.body})
});
}
componentDidMount() {
this.refreshData();
setInterval(this.refreshData(), 30000);
}
A route in the backend looks like this
@app.route("/cData")
def cData():
#do work
return jsonify(work)
The return data of each flask route will be in JSON form (dictionary)
Any idea what I need to do on the client side (React) to really get this done? Rather than using the threading module in Python (since that does not allow multiple threads to run at the same time) is there a different way? Multi-processing?