Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect CompletableFuture integration #1088

Merged
merged 12 commits into from
Sep 21, 2023
37 changes: 7 additions & 30 deletions project/TaglessGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -366,38 +366,15 @@ class TaglessGen(
|
| ${managed.map(interpreterDef).mkString("\n ")}
| // Some methods are common to all interpreters and can be overridden to change behavior globally.
|
| def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
| def primitive1[J, A](f: =>A): M[A] = asyncM.blocking(f)
|
| def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
| asyncM.async_ { cb =>
| fut(a).handle[Unit] { (a, x) =>
| if (a == null)
| x match {
| case t: CompletionException => cb(Left(t.getCause))
| case t => cb(Left(t))
| }
| else
| cb(Right(a))
| }
| ()
| }
| }
| def eff1[J, A](fut: =>CompletableFuture[A]): M[A] =
| asyncM.async_ { cb =>
| fut.handle[Unit] { (a, x) =>
| if (a == null)
| x match {
| case t: CompletionException => cb(Left(t.getCause))
| case t => cb(Left(t))
| }
| else
| cb(Right(a))
| }
| ()
| }
| def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
| def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)
|
| def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
| asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
| }
| def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
| asyncM.fromCompletableFuture(asyncM.delay(fut))
|
| // Interpreters
|${managed.map(ClassTag(_)).map(kleisliInterp(_)).mkString("\n")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import cats.data.Kleisli
import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClientBuilder

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient
import software.amazon.awssdk.services.cloudwatch.model.*
Expand All @@ -32,36 +30,14 @@ trait Interpreter[M[_]] { outer =>
lazy val CloudWatchAsyncClientInterpreter: CloudWatchAsyncClientInterpreter = new CloudWatchAsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait CloudWatchAsyncClientInterpreter extends CloudWatchAsyncClientOp[Kleisli[M, CloudWatchAsyncClient, *]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import cats.data.Kleisli
import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientBuilder

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient
import software.amazon.awssdk.services.dynamodb.model.*
Expand All @@ -32,36 +30,14 @@ trait Interpreter[M[_]] { outer =>
lazy val DynamoDbAsyncClientInterpreter: DynamoDbAsyncClientInterpreter = new DynamoDbAsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait DynamoDbAsyncClientInterpreter extends DynamoDbAsyncClientOp[Kleisli[M, DynamoDbAsyncClient, *]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import cats.data.Kleisli
import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.kinesis.KinesisAsyncClientBuilder

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient
import software.amazon.awssdk.services.kinesis.model.*
Expand All @@ -32,36 +30,14 @@ trait Interpreter[M[_]] { outer =>
lazy val KinesisAsyncClientInterpreter: KinesisAsyncClientInterpreter = new KinesisAsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait KinesisAsyncClientInterpreter extends KinesisAsyncClientOp[Kleisli[M, KinesisAsyncClient, *]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.s3.S3AsyncClientBuilder
import software.amazon.awssdk.services.s3.model.*

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.core.async.{AsyncRequestBody, AsyncResponseTransformer}
import software.amazon.awssdk.services.s3.S3AsyncClient
Expand All @@ -34,36 +32,14 @@ trait Interpreter[M[_]] { outer =>
lazy val S3AsyncClientInterpreter: S3AsyncClientInterpreter = new S3AsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait S3AsyncClientInterpreter extends S3AsyncClientOp[Kleisli[M, S3AsyncClient, *]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import cats.data.Kleisli
import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.sns.SnsAsyncClientBuilder

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.services.sns.SnsAsyncClient
import software.amazon.awssdk.services.sns.model.*
Expand All @@ -32,36 +30,14 @@ trait Interpreter[M[_]] { outer =>
lazy val SnsAsyncClientInterpreter: SnsAsyncClientInterpreter = new SnsAsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait SnsAsyncClientInterpreter extends SnsAsyncClientOp[Kleisli[M, SnsAsyncClient, *]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import cats.data.Kleisli
import cats.effect.{Async, Resource}
import software.amazon.awssdk.services.sqs.SqsAsyncClientBuilder

import java.util.concurrent.CompletionException

// Types referenced
import software.amazon.awssdk.services.sqs.SqsAsyncClient
import software.amazon.awssdk.services.sqs.model.*
Expand All @@ -32,36 +30,14 @@ trait Interpreter[M[_]] { outer =>
lazy val SqsAsyncClientInterpreter: SqsAsyncClientInterpreter = new SqsAsyncClientInterpreter {}
// Some methods are common to all interpreters and can be overridden to change behavior globally.

def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(a => asyncM.blocking(f(a)))
def primitive[J, A](f: J => A): Kleisli[M, J, A] = Kleisli(j => asyncM.blocking(f(j)))
def primitive1[J, A](f: => A): M[A] = asyncM.blocking(f)

def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { a =>
asyncM.async_ { cb =>
fut(a).handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
def eff[J, A](fut: J => CompletableFuture[A]): Kleisli[M, J, A] = Kleisli { j =>
asyncM.fromCompletableFuture(asyncM.delay(fut(j)))
}
def eff1[J, A](fut: => CompletableFuture[A]): M[A] =
asyncM.async_ { cb =>
fut.handle[Unit] { (a, x) =>
if (a == null)
x match {
case t: CompletionException => cb(Left(t.getCause))
case t => cb(Left(t))
}
else
cb(Right(a))
}
()
}
asyncM.fromCompletableFuture(asyncM.delay(fut))

// Interpreters
trait SqsAsyncClientInterpreter extends SqsAsyncClientOp[Kleisli[M, SqsAsyncClient, *]] {
Expand Down
Loading