Last active
April 18, 2021 04:03
-
-
Save MufidJamaluddin/69fd90f98472ba44d386fbf83b9879f1 to your computer and use it in GitHub Desktop.
ASP.NET Core Asinkronus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebAPI | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// Batasi maksimal thread jadi sesuai dengan jumlah CPU | |
var processorCounter = Environment.ProcessorCount; | |
ThreadPool.SetMaxThreads( | |
processorCounter, | |
processorCounter | |
); | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) | |
{ | |
return Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseStartup<Startup>(); | |
}); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Web.Controllers.v1 | |
{ | |
[ApiController] | |
[Route("api/v1/[controller]")] | |
public class WeatherForecastController : ControllerBase | |
{ | |
[HttpGet] | |
public async Task<IActionResult> Get() // Pake keyword "async Task" | |
{ | |
var data = await WheaterUseCase.execute() | |
.Select(wheater => new WeatherForecast | |
{ | |
Date = wheater.date, | |
TemperatureC = wheater.temperature.Celcius, | |
Summary = wheater.summary | |
}); | |
return Ok(data); | |
} | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment