Skip to content

Instantly share code, notes, and snippets.

View mantzas's full-sized avatar
🏍️
hacking

Sotirios Mantziaris mantzas

🏍️
hacking
View GitHub Profile
package main
import (
common_http "bitusion.com/TradingSimulator/common/net/http"
"bitusion.com/TradingSimulator/services/order_command_service/handlers"
log "github.com/Sirupsen/logrus"
"net/http"
_ "net/http/pprof"
"os"
)
package main
import (
"fmt"
)
func main() {
msg := "Hello World!"
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch main.go",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/.",
"env": {},
@mantzas
mantzas / HomeController.cs
Created May 26, 2016 19:35
Deadlock example on ASP.NET MVC Controller
public class HomeController : Controller
{
public ActionResult Index()
{
var jsonTask = GetJsonDeadLockAsync(new Uri("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"));
//var jsonTask = GetJsonAsync(new Uri("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"));
var result = jsonTask.Result.ToString(); // this here blocks the initial thread along with it's context
return View();
}
public void Test()
{
// Cold Task
var t = new Task(() => Console.WriteLine());
// Hot Task
t.Start(); //now it's hot
var tHot1 = Task.Run(()=>Console.WriteLine());
var tHot2 = GetJsonAsync(new Uri("http://......"));
}
public async Task WhenAnyWhenAll()
{
var t = Task.Run(() => Console.WriteLine());
await Task.WhenAny(t);
await Task.WhenAll(t);
}
public async Task AwaitMultiple()
{
var t1 = Task.Run(() => Console.WriteLine());
var t2 = Task.Run(() => Console.WriteLine());
var t3 = Task.Run(() => Console.WriteLine());
var t4 = Task.Run(() => Console.WriteLine());
await t1;
await t2;
await t3;
public async Task SleepTaskDelay()
{
Thread.Sleep(1000);
//vs
await Task.Delay(1000);
}
public async Task SemaphoreSlim()
{
var s = new SemaphoreSlim(1, 1);
var entered = await s.WaitAsync(1000);
if(entered)
{
//actual code
}
public async Task AwaitAsync()
{
await Task.Run(() => Console.WriteLine(""));
}
public Task AwaitNormal()
{
return Task.Run(() => Console.WriteLine(""));
}