![]() |
creating a delay - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: creating a delay (/showthread.php?tid=79528) Pages:
1
2
|
creating a delay - richb201 - 06-28-2021 In one section of my code I use koolreport to build a "complex" report. My database is mysql on AWS RDS, so it is remote from my laptop. I am finding that "sometimes" the data doesn't arrive timely to populate a koolreport structure that I am using to create the report. So sometimes that section of the report is blank because the array hasn't been fully populated. I think I can check to see if it is populated with if !empty(dataStructure) then go ahead, otherwise wait for a few seconds and then check again. How can I put this delay/test into my CI3 app? RE: creating a delay - php_rocs - 06-29-2021 @richb201, You could use the sleep function in PHP. https://www.php.net/manual/en/function.sleep.php RE: creating a delay - richb201 - 06-29-2021 (06-29-2021, 06:11 AM)php_rocs Wrote: @richb201, thx Rocs. I will investigate. RE: creating a delay - includebeer - 06-29-2021 I don't know how you call this report, but calling sleep is never reliable. Maybe a more reliable way to do this would be to make an ajax call to the backend and when the data is ready call a callback function to run the report. RE: creating a delay - paulbalandan - 06-30-2021 Use Promises or async/await RE: creating a delay - richb201 - 06-30-2021 (06-30-2021, 01:03 AM)paulbalandan Wrote: Use Promises or async/await RE: creating a delay - richb201 - 07-08-2021 Well, I am still having an issue with this. I am using koolreport which is not super fast. When I call my page it renders most of the page but there is one section of charts that usually (i'd say 80% of the time) doesn't render on the first try, on a large report. Now if I then press the browser refresh, the chart then appears. Seems to me that the browser page is displaying before koolreport engine is done rendering. When I press refresh, no new code is running, right? The vender of koolereport is intent on me debugging this myself and that my data is not appearing fast enough. I am getting data from AWS RDS and then processing it. My sql sucks. But CI3 is synchronous, not async, right? I think the fact that the refresh works 100% of the time means something else is happening and it might not be a great answer but slowing down the browser might be my only option? How about delaying for a few seconds and then having CI3 call for a refresh? Perhaps the answer is refreshing the browser window from my CI3 application? People have mentioned using sleep. but how can I sleep the browser without sleeping the CI3 processing the data? Well, I am still having an issue with this. I am using koolreport which is not super fast. When I call my page it renders most of the page but there is one section of charts that usually (i'd say 80% of the time) don't render on the first try. Now if I then press the browser refresh, the chart then appears. Seems to me that the page is displaying before the rendering is done. When I press refresh, no new code is running. The vender koolereport is intent on me debugging this and that my data is not appearing fast enough. I am getting data from AWS RDS. Is the data being loaded asynch? I think the fact that the refresh works 100% of the times means something else is happening and it might not be a great answer but slowing down the browser might be my only option? RE: creating a delay - John_Betong - 07-08-2021 @richb201, Have you tried saving the report results to a web page and a link to the latter which should render a lot quicker? RE: creating a delay - richb201 - 07-08-2021 (07-08-2021, 05:55 PM)John_Betong Wrote: @richb201,What do you mean John? Exporting to a pdf and supplying a link to it? Koolreport does have an export tool but I was just trying that and couldn't get it working (at all). How does one save to a web page w/o rendering it first? On a slightly different take on this same thing, on my report, a user can change the taxyear. <php if (isset($_POST['taxyear'])) $_SESSION['last_TY']=$_POST['taxyear']; header("Refresh:0"); ?> This seems to work except it keeps refreshing about once per second. RE: creating a delay - paliz - 07-09-2021 function delay(t, v) { return new Promise(function(resolve) { setTimeout(resolve.bind(null, v), t) }); } Promise.prototype.delay = function(t) { return this.then(function(v) { return delay(t, v); }); } Promise.resolve("hello").delay(500).then(function(v) { console.log(v); }); |