This file contains 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
import io.ktor.network.tls.certificates.buildKeyStore | |
import io.ktor.network.tls.certificates.saveToFile | |
import io.ktor.network.tls.extensions.HashAlgorithm | |
import io.ktor.network.tls.extensions.SignatureAlgorithm | |
import io.ktor.routing.routing | |
import io.ktor.server.engine.applicationEngineEnvironment | |
import io.ktor.server.engine.embeddedServer | |
import io.ktor.server.engine.sslConnector | |
import io.ktor.server.netty.Netty | |
import io.ktor.server.netty.NettyApplicationEngine |
This file contains 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
select a[1]::integer as col1, a[2]::integer as col2, a[3]::float as col3, a[4] as col4, a[5] as col5 | |
from ( | |
select string_to_array(nest.l, ',') as a | |
from ( | |
select unnest('{"3,2,82.38,null,World","4,1,43.12,Hello,null"}'::text[]) as l | |
) nest | |
) b; |
This file contains 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
final VertxOptions options = new VertxOptions().setEventLoopPoolSize(4); | |
Vertx vertx = Vertx.vertx(options); |
This file contains 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
func (this *future[T]) Get() Result[T] { | |
if this.completed { | |
return this.result | |
} else { | |
fmt.Println("Need to wait...") | |
select { | |
case <-this.wait: | |
return this.result | |
case <-this.ctx.Done(): | |
return &result(T){failure: this.ctx.Err()} |
This file contains 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
sealed class KIO<out A : Any?> { | |
... | |
fun <B> recover(f: (Throwable) -> KIO<B>): Recovery<B> { | |
return Recovery(this, f) | |
} | |
} | |
... |
This file contains 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
fun main() { | |
Runtime.unsafeRunSync( | |
Effect { | |
// Generate some random UUID | |
if (Random().nextBoolean()) { | |
UUID.randomUUID().toString() | |
} | |
else { | |
null | |
} |
This file contains 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
fun main() { | |
Runtime.unsafeRunSync( | |
Effect { | |
// Generate some random UUID | |
UUID.randomUUID().toString() | |
}.map { | |
// Print it | |
println("UUID: $it") | |
} | |
) |
This file contains 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
object Runtime { | |
fun <A> unsafeRunSync(kio: KIO<A>): A = eval(kio) | |
fun <A> eval(kio: KIO<A>): A { | |
return when (kio) { | |
is Effect<A> -> kio.f() | |
is FlatMap<*, A> -> { | |
val res: Any? = eval(kio.input) | |
val f = kio.f as (Any?) -> KIO<A> | |
eval(f(res)) |
This file contains 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
sealed class KIO<out A> { | |
fun <B> flatMap(f: (A) -> KIO<B>): KIO<B> { | |
return FlatMap(this, f) | |
} | |
fun <B> map(f: (A) -> B): KIO<B> { | |
return flatMap { a -> | |
Effect { | |
f(a) | |
} |
This file contains 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
for (var i = 0; i < 1_000_000; i++) { | |
Thread.startVirtualThread(() -> { | |
c.incrementAndGet(); | |
try { | |
Thread.sleep(1_000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
}); | |
} |
NewerOlder