Permalink
Browse files

add railo compatibility to debounce

to fix the "Missing parent Statement of Statement" railo bug
  • Loading branch information...
1 parent 48e84a1 commit 4083e0476abdf35a9bd2e680894e88365275cb2b @russplaysguitar committed Dec 29, 2012
Showing with 15 additions and 10 deletions.
  1. +15 −10 Underscore.cfc
View
@@ -1329,26 +1329,31 @@ component {
var threadName = '_debounced_x';
var called = false;
var setCalled = function(v){ called = v; };
- return function () {
- if (structKeyExists(cfthread, threadName) && cfthread[threadName].status neq "completed"){
+ return function() {
+ if (isdefined('cfthread') && structKeyExists(cfthread, threadName) && cfthread[threadName].status neq "completed"){
@russplaysguitar

russplaysguitar Dec 29, 2012

Owner

I couldn't think of any other way to check for the existence of the cfthread scope other than isdefined(). Please speak up if there is a better way!

@atuttle

atuttle Dec 29, 2012

Contributor

Don't think I could have done any better. I assume the cfthread scope works the same in Railo, but I'm assuming it's just not available when threads haven't been started?

@russplaysguitar

russplaysguitar Dec 29, 2012

Owner

Yeah, oddly in Railo it isn't available if there is only the single (main) thread. Hopefully isdefined() doesn't slow things down too much.

thread action='terminate' name=threadName;
}
threadCount++;
threadName = threadNameBase & threadCount;
- if (!structKeyExists(cfthread, threadName)){
- thread action='run' name=threadName wait=wait func=func immediate=immediate setCalled=setCalled called=called {
- if (immediate && !called) func();
- setCalled(true);
- sleep(attributes.wait);
- if (!immediate) func();
- setCalled(false);
- }
+ if (!isdefined('cfthread') || !structKeyExists(cfthread, threadName)){
+ debounceThread(threadName, wait, func, immediate, setCalled, called);
}else{
throw;
}
};
}
+ // this is a separate, "named" function for Railo compatibility only
+ private function debounceThread(threadName, wait, func, immediate, setCalled, called) {
+ thread action='run' name=threadName wait=wait func=func immediate=immediate setCalled=setCalled called=called {
+ if (immediate && !called) func();
+ setCalled(true);
+ sleep(attributes.wait);
+ if (!immediate) func();
+ setCalled(false);
+ }
+ }
+
/**
* @header _.once(function) : function
* @hint Returns a function that will be executed at most one time, no matter how often you call it. Useful for lazy initialization.

0 comments on commit 4083e04

Please sign in to comment.