diff --git a/lib/std.js b/lib/std.js index 3d8a4d8..72276f4 100644 --- a/lib/std.js +++ b/lib/std.js @@ -342,15 +342,23 @@ function AsyncFunction(f) { this.f = f; this.run = function() { + AsyncFunction.counter++; // increase number of async functions + + var _this = this; + var f = function() { + _this.f(); + AsyncFunction.counter--; // decrease number of async functions + }; + if (this.proxyWindow != null) { try { - this.proxyWindow.setTimeout(1, this.f); + this.proxyWindow.setTimeout(1, f); } catch (e) { console.warn("AsyncFunction proxyWindow.setTimeout failed:", e.message); - sleep(1, this.f); + sleep(1, f); } } else { - sleep(1, this.f); + sleep(1, f); } }; @@ -368,6 +376,7 @@ function AsyncFunction(f) { } } }; +AsyncFunction.counter = 0; // static variable global.GetResource = GetResource; global.sleep = sleep;