Reputation: 155
In my webapp I use SailsJS backend to fetch data from an API (facebook graph api) and that fetched data will be saved on the database on the backend when it has finished fetched.
So my question is when I make a request to the backend to do all this work how do I show the user how much of it has been completed. At the moment all I can show is a loading icon. But I like to show something like 1% completed, 89% completed as such
a sailsjs app create 1000 records on the backend. Right. and when every record has been created i need to know while im on the frontend. You know what I mean ? I need a response to the web browser saying 1/1000 record has been created
Please help me here if you are familiar with the framework
Cheers.
Upvotes: 0
Views: 666
Reputation: 5979
Essentially you can loop through your record create in some fashion then use response.write() to stream updates to the user. This is a crude example:
function doStuff(req,res){
// You can use response.write() to do what you need.
var processedRecords = 0;
var totalRecords = 1000;
res.status(200);
while (processRecords < totalRecords){
Model.create( --create model stuff-- , function(){
processedRecords++;
res.write('Finished ' + processedRecords + 'of ' + totalRecords);
})
}
return res.end();
}
Upvotes: 1