Skip to content

Instantly share code, notes, and snippets.

View CanerPatir's full-sized avatar
🚀

Caner Patır CanerPatir

🚀
View GitHub Profile
@CanerPatir
CanerPatir / A lightweight message bus using TPL DataFlow
Last active July 26, 2023 08:02 — forked from benfoster/gist:4416655
A lightweight message bus using TPL DataFlow
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace TDFDemo
{
class Program
{
@CanerPatir
CanerPatir / PipelineStep.java
Last active August 25, 2020 21:48
Simple pipeline implementation to supply fluent and readable DSLs for business workflows through using Java 8 functional features
@FunctionalInterface
public interface PipelineStep<I, O, Ctx> {
static <I, O, Ctx> PipelineStep<I, O, Ctx> of(PipelineStep<I, O, Ctx> source) {
return source;
}
O execute(I value, Ctx context) throws Exception;
default <R> PipelineStep<I, R, Ctx> pipe(PipelineStep<O, R, Ctx> next) {
@CanerPatir
CanerPatir / MyTask.cs
Last active April 22, 2019 16:39
Simple in memory scheduled job implementation for .net core
public class MyTask : ScheduleTask
{
public MyTask(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
{
}
protected override string CronExpression => "*/10 * * * *";
public override Task Execute(IServiceProvider serviceProvider)
{
#!/bin/zsh
for i in */.git;
do ( echo $i; cd $i/..; git pull; git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done );
done
@CanerPatir
CanerPatir / suspend-function.kt
Last active September 15, 2019 09:43
Kotlin-Coroutine
suspend fun someSuspendableOperation(): String {
delay(1000L) // representation of IO operation like going to DB
return "hello"
}
suspend fun doOperation1() {
delay(1000L)
}
suspend fun getSomeResult(): String {
delay(2000L)
return "hello"
}
fun main(){
fun main() {
runBlocking {
val deferred1 = async { operation1() }
val deferred2 = async { operation2() }
println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] Awaiting computations...")
val result = deferred1.await() + deferred2.await()
println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] The result is $result")
}
}
fun main() {
runBlocking {
val deferred1 = async { operation1() }
val deferred2 = async { operation2() }
println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] Awaiting computations...")
val result = deferred1.await() + deferred2.await()
println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] The result is $result")
}
}
fun main() = runBlocking {
GlobalScope.launch {
delay(1000L)
print("World!")
}
print("Hello")
}
fun concurrencyTest(){
val time1 = measureTimeMillis {
runBlocking {
val listOfDeferred: List<Deferred<Int>> = (1..50).map { i ->
async {
delay(100)
Int.MIN_VALUE
}
}
}