Welcome Guest, Not a member yet? Register   Sign In
creating a delay
#1

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?
proof that an old dog can learn new tricks
Reply
#2

@richb201,

You could use the sleep function in PHP. https://www.php.net/manual/en/function.sleep.php
Reply
#3

(06-29-2021, 06:11 AM)php_rocs Wrote: @richb201,

You could use  the sleep function in PHP. https://www.php.net/manual/en/function.sleep.php

thx Rocs. I will investigate.
proof that an old dog can learn new tricks
Reply
#4

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.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

Use Promises or async/await
Reply
#6

(06-30-2021, 01:03 AM)paulbalandan Wrote: Use Promises or async/await

Thanks. Can you recommend a good white paper/tutorial on the use of Promises?
proof that an old dog can learn new tricks
Reply
#7

(This post was last modified: 07-08-2021, 05:11 PM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#8

@richb201,

Have you tried saving the report results to a web page and a link to the latter which should render a lot quicker?
Reply
#9

(This post was last modified: 07-08-2021, 08:20 PM by richb201.)

(07-08-2021, 05:55 PM)John_Betong Wrote: @richb201,

Have you tried saving the report results to a web page and a link to the latter which should render a lot quicker?
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.
proof that an old dog can learn new tricks
Reply
#10

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);
});
Enlightenment  Is  Freedom
Reply




Theme © iAndrew 2016 - Forum software by © MyBB