Skip to content

Conversation

@RibleStrype
Copy link
Contributor

Even though semantically the behaviour is the same, I think it is a bit cleaner when we don't "unsafely" run the effect (completing Deferred) via ToTry in Producer#send callback.

Also as the docs state the Callback is generally executed in the I/O thread of the producer, so it should be as fast as possible. To me it seems that completing a Promise is more lightweight than executing an effect of completing Deferred.

@coveralls
Copy link

coveralls commented Feb 14, 2022

Pull Request Test Coverage Report for Build 1841127528

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 33 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-1.8%) to 83.129%

Files with Coverage Reduction New Missed Lines %
skafka/src/main/scala/com/evolutiongaming/skafka/consumer/ConsumerConverters.scala 1 95.08%
skafka/src/main/scala/com/evolutiongaming/skafka/Converters.scala 1 89.39%
skafka/src/main/scala/com/evolutiongaming/skafka/producer/ProducerLogging.scala 1 52.94%
skafka/src/main/scala/com/evolutiongaming/skafka/consumer/ConsumerLogging.scala 30 68.93%
Totals Coverage Status
Change from base Build 1751109306: -1.8%
Covered Lines: 1291
Relevant Lines: 1553

💛 - Coveralls

def block(record: ProducerRecordJ[Bytes, Bytes]) = {

def callbackOf(deferred: Deferred[F, Either[Throwable, RecordMetadataJ]]): Callback = {
def callbackOf(promise: Promise[RecordMetadataJ]): Callback = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think that this is anyhow faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't measured it of course, it just intuitively feels more lightweight, but I don't have any strong arguments in this regard.

Copy link
Contributor

@t3hnar t3hnar Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend keep using deferred but call toFuture instead of toTry and deprecate API requiring ToTry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how is ToFuture better than ToTry, don't they both call unsafeRunSync in implementation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how is ToFuture better than ToTry, don't they both call unsafeRunSync in implementation?

  1. less construction requirements
  2. ToFuture uses unsafeToFuture, and truly saying both are ok in this case

Copy link
Contributor Author

@RibleStrype RibleStrype Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I change ToTry to ToFuture what do I do with the resulting Future? Do I await inside the Callback or just ignore it? TBH I don't like any of these options and would rather leave ToTry then.
btw, what's the reason you are against using Promise here? To me it seems cleaner that materialising an effect in any manner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I await inside the Callback or just ignore it?

Just ignore it, as executed code is private and you exactly know what is being executed

Copy link
Contributor

@t3hnar t3hnar Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you are against using Promise here

Because that combination of Promise/Future adds more overhead than you might think of comparing to native, it is also not a cancellable thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this particular use case is not cancellable either way, is it? Even if you cancel the resulting effect the producer's callback will still be executed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean cancelling the "inner" effect resulting from Deferred#get

}

def of[F[_]: ToTry: Async](
def of[F[_]: Async](
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaks backward compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though it might break it, but MiMa checks passing kinda convinced me otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you mean source compatibility?

}

@deprecated("Use of(ProducerConfig)", since = "12.0.1")
def of[F[_]: ToTry: Async](
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaks backward compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how does MiMa check pass then?

Copy link
Contributor

@t3hnar t3hnar Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how does MiMa check pass then?

good question, should not pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants