Let's say I have a function called takesFiveSeconds()
. I want to see the outcome after it's finished.
takesFiveSeconds()
writeDump(outcome); // don't execute until takesFiveSeconds is finished
abort;
// the rest of the code runs //
How can I accomplish this? I understand CF doesn't have promises yet.
Here's what I've tried:
thread name="t1"
{
takesFiveSeconds()
}
thread name="t2"
{
threadjoin("t1",1000);
writeDump(outcome);
abort;
}
threadjoin("t2");
I'm not sure if this works because the site finishes loading before it hits the abort, and I never see the writeDump
s.
Sleep
takesFiveSeconds()
Sleep(15000);
writeDump(outcome);
abort;
All this does is take an extra long time to tell me outcome
was dumped before takesFiveSeconds()` finished.
Here is the simple approach:
<cfset start_time = now()>
<cfloop condition="DateDiff('s', start_time, now()) LT 5">
<cfset tmp = "wait">
</cfloop>