Skip to content

Instantly share code, notes, and snippets.

View eugeniyk's full-sized avatar
🎯

Eugene eugeniyk

🎯
View GitHub Profile
@eugeniyk
eugeniyk / InnerInterruptionCorrectExample.java
Created September 13, 2023 21:19
Demonstration of the case where inner future does receive an interruption signal - outerExecutorService lambda explicitly catch it
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
public class InnerInterruptionCorrectExample {
public static void main(String[] args) throws InterruptedException {
// Create a ExecutorService for managing threads
@eugeniyk
eugeniyk / InnerInterruptionTest.java
Created September 13, 2023 21:14
Demonstration of the case where inner future doesn't receive interruption signal - it has to be explicitly set by outerExecutorService lambda
package com.glovoapp.jvmkit.context.demo.app.models;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
public class InnerInterruptionTest {
public static void main(String[] args) throws InterruptedException {
@eugeniyk
eugeniyk / jaeger-to-opentelemetry-pom.xml
Created December 1, 2021 06:22
Migration to opentelemetry tutorial final pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>java-opentracing-tutorial</name>
<groupId>com.github.yurishkuro</groupId>
<artifactId>java-opentracing-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
trait KVStore[F[_], K, V] {
def get(key: K): F[Option[V]]
def put(key: K, value: V): F[Unit]
}
class Dict[F[_]: Monad, K, V](store: KVStore[F, K, V]) {
def computeIfAbsent(k: K, absent: => V)(implicit m: Monad[F]): F[V] = {
m.flatMap(store.get(k)) { value =>
m.pure(value.getOrElse(absent))
}