fable 3.0.103 → 3.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.103",
3
+ "version": "3.0.105",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
package/source/Fable.js CHANGED
@@ -101,6 +101,11 @@ class Fable extends libFableServiceBase.CoreServiceProviderBase
101
101
  return this.UUID.getUUID();
102
102
  }
103
103
 
104
+ newAnticipate()
105
+ {
106
+ return this.instantiateServiceProviderWithoutRegistration('Anticipate');
107
+ }
108
+
104
109
  /* Service Manager Methods */
105
110
  addServiceType(pServiceType, pServiceClass)
106
111
  {
@@ -15,6 +15,8 @@ class FableServiceAnticipate extends libFableServiceBase
15
15
  this.executingOperationCount = 0;
16
16
  this.completedOperationCount = 0;
17
17
 
18
+ this.callDepth = 0;
19
+
18
20
  this.maxOperations = 1;
19
21
 
20
22
  this.lastError = undefined;
@@ -60,8 +62,8 @@ class FableServiceAnticipate extends libFableServiceBase
60
62
  Called: false,
61
63
  Error: undefined,
62
64
  OperationSet: this
63
- });
64
- return hoistedCallback;
65
+ });
66
+ return hoistedCallback.bind(this);
65
67
  function hoistedCallback(pError)
66
68
  {
67
69
  if (tmpCallbackState.Called)
@@ -75,7 +77,18 @@ class FableServiceAnticipate extends libFableServiceBase
75
77
  tmpCallbackState.OperationSet.executingOperationCount -= 1;
76
78
  tmpCallbackState.OperationSet.completedOperationCount += 1;
77
79
 
78
- tmpCallbackState.OperationSet.checkQueue();
80
+ tmpCallbackState.OperationSet.callDepth++;
81
+
82
+ // TODO: Figure out a better pattern for chaining templates so the call stack doesn't get abused.
83
+ if (tmpCallbackState.OperationSet.callDepth > 400)
84
+ {
85
+ tmpCallbackState.OperationSet.callDepth = 0;
86
+ setTimeout(tmpCallbackState.OperationSet.checkQueue.bind(this), 0);
87
+ }
88
+ else
89
+ {
90
+ tmpCallbackState.OperationSet.checkQueue();
91
+ }
79
92
  }
80
93
  }
81
94
 
@@ -58,7 +58,7 @@ suite
58
58
  function (fTestComplete)
59
59
  {
60
60
  let testFable = new libFable();
61
- let tmpAnticipate = testFable.instantiateServiceProvider('Anticipate');
61
+ let tmpAnticipate = testFable.newAnticipate();
62
62
  tmpAnticipate.maxOperations = 2;
63
63
  tmpAnticipate.anticipate(function (fCallback)
64
64
  {
@@ -85,6 +85,30 @@ suite
85
85
  });
86
86
  }
87
87
  );
88
+ test
89
+ (
90
+ 'Huge call stack',
91
+ function (fTestComplete)
92
+ {
93
+ this.timeout(10000);
94
+ let testFable = new libFable();
95
+ let tmpAnticipate = testFable.instantiateServiceProvider('Anticipate');
96
+
97
+ for (let i = 0; i < 50000; i++)
98
+ {
99
+ tmpAnticipate.anticipate(function (fCallback)
100
+ {
101
+ return fCallback();
102
+ });
103
+ }
104
+
105
+ tmpAnticipate.wait(function (pError)
106
+ {
107
+ testFable.log.info(`Waits completed!`)
108
+ return fTestComplete();
109
+ });
110
+ }
111
+ );
88
112
  }
89
113
  );
90
114
  }