Skip to content

Commit a036b92

Browse files
committed
Allow configuration of number of JavaScript engines in the pool in IReactSiteConfiguration
1 parent c467869 commit a036b92

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

src/React/IReactSiteConfiguration.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,27 @@ public interface IReactSiteConfiguration
7777
/// Sets whether Flow types should be stripped out.
7878
/// </summary>
7979
IReactSiteConfiguration SetStripTypes(bool stripTypes);
80+
81+
/// <summary>
82+
/// Gets or sets the number of engines to initially start when a pool is created.
83+
/// Defaults to <c>10</c>.
84+
/// </summary>
85+
int? StartEngines { get; set; }
86+
/// <summary>
87+
/// Sets the number of engines to initially start when a pool is created.
88+
/// Defaults to <c>10</c>.
89+
/// </summary>
90+
IReactSiteConfiguration SetStartEngines(int? startEngines);
91+
92+
/// <summary>
93+
/// Gets or sets the maximum number of engines that will be created in the pool.
94+
/// Defaults to <c>25</c>.
95+
/// </summary>
96+
int? MaxEngines { get; set; }
97+
/// <summary>
98+
/// Sets the maximum number of engines that will be created in the pool.
99+
/// Defaults to <c>25</c>.
100+
/// </summary>
101+
IReactSiteConfiguration SetMaxEngines(int? maxEngines);
80102
}
81103
}

src/React/JavaScriptEngineFactory.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,21 @@ IFileSystem fileSystem
107107
/// </summary>
108108
protected virtual IJsPool CreatePool()
109109
{
110-
return new JsPool(new JsPoolConfig
110+
var poolConfig = new JsPoolConfig
111111
{
112112
EngineFactory = _factory,
113113
Initializer = InitialiseEngine,
114-
});
114+
};
115+
if (_config.MaxEngines != null)
116+
{
117+
poolConfig.MaxEngines = _config.MaxEngines.Value;
118+
}
119+
if (_config.StartEngines != null)
120+
{
121+
poolConfig.StartEngines = _config.StartEngines.Value;
122+
}
123+
124+
return new JsPool(poolConfig);
115125
}
116126

117127
/// <summary>

src/React/ReactSiteConfiguration.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,35 @@ public IReactSiteConfiguration SetStripTypes(bool stripTypes)
124124
StripTypes = stripTypes;
125125
return this;
126126
}
127+
128+
/// <summary>
129+
/// Gets or sets the number of engines to initially start when a pool is created.
130+
/// Defaults to <c>10</c>.
131+
/// </summary>
132+
public int? StartEngines { get; set; }
133+
/// <summary>
134+
/// Sets the number of engines to initially start when a pool is created.
135+
/// Defaults to <c>10</c>.
136+
/// </summary>
137+
public IReactSiteConfiguration SetStartEngines(int? startEngines)
138+
{
139+
StartEngines = startEngines;
140+
return this;
141+
}
142+
143+
/// <summary>
144+
/// Gets or sets the maximum number of engines that will be created in the pool.
145+
/// Defaults to <c>25</c>.
146+
/// </summary>
147+
public int? MaxEngines { get; set; }
148+
/// <summary>
149+
/// Sets the maximum number of engines that will be created in the pool.
150+
/// Defaults to <c>25</c>.
151+
/// </summary>
152+
public IReactSiteConfiguration SetMaxEngines(int? maxEngines)
153+
{
154+
MaxEngines = maxEngines;
155+
return this;
156+
}
127157
}
128158
}

0 commit comments

Comments
 (0)