mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Create new top-level DefaultNodeInstance concept that will soon hold the "connection draining" logic
This commit is contained in:
@@ -12,21 +12,21 @@ namespace ConsoleApplication
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args) {
|
||||
using (var nodeServices = CreateNodeServices(Configuration.DefaultNodeHostingModel)) {
|
||||
using (var nodeServices = CreateNodeServices(NodeServicesOptions.DefaultNodeHostingModel)) {
|
||||
MeasureLatency(nodeServices).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task MeasureLatency(INodeServices nodeServices) {
|
||||
// Ensure the connection is open, so we can measure per-request timings below
|
||||
var response = await nodeServices.Invoke<string>("latencyTest", "C#");
|
||||
var response = await nodeServices.InvokeAsync<string>("latencyTest", "C#");
|
||||
Console.WriteLine(response);
|
||||
|
||||
// Now perform a series of requests, capturing the time taken
|
||||
const int requestCount = 100;
|
||||
var watch = Stopwatch.StartNew();
|
||||
for (var i = 0; i < requestCount; i++) {
|
||||
await nodeServices.Invoke<string>("latencyTest", "C#");
|
||||
await nodeServices.InvokeAsync<string>("latencyTest", "C#");
|
||||
}
|
||||
|
||||
// Display results
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace NodeServicesExamples.Controllers
|
||||
}
|
||||
|
||||
// Invoke Node and pipe the result to the response
|
||||
var imageStream = await _nodeServices.Invoke<Stream>(
|
||||
var imageStream = await _nodeServices.InvokeAsync<Stream>(
|
||||
"./Node/resizeImage",
|
||||
fileInfo.PhysicalPath,
|
||||
mimeType,
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace NodeServicesExamples
|
||||
if (requestPath.StartsWith("/js/") && requestPath.EndsWith(".js")) {
|
||||
var fileInfo = env.WebRootFileProvider.GetFileInfo(requestPath);
|
||||
if (fileInfo.Exists) {
|
||||
var transpiled = await nodeServices.Invoke<string>("./Node/transpilation.js", fileInfo.PhysicalPath, requestPath);
|
||||
var transpiled = await nodeServices.InvokeAsync<string>("./Node/transpilation.js", fileInfo.PhysicalPath, requestPath);
|
||||
await context.Response.WriteAsync(transpiled);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user