monix-connect icon indicating copy to clipboard operation
monix-connect copied to clipboard

All APIs should be lazy

Open rfkm opened this issue 3 years ago • 2 comments

When wrapping a CompletableFuture with a Task, Task.from is often used in this library. However, this means that the CompletableFuture will be executed even if the Task is not evaluated (i.e., it is not referential transparent). This is not the expected behavior for many users.

e.g. https://github.com/monix/monix-connect/blob/cb3f2c243c2fcc02799a2470576497ae2ddef2d8/s3/src/main/scala/monix/connect/s3/S3.scala#L714-L715

I think it is correct to use Task.fromFutureLike.

rfkm avatar Sep 29 '22 10:09 rfkm

Actually, from is implicitly using fromFutureLike via fromAnyFutureViaLift. But I think that your point is still valid and to make the referential transparent we should wrap it with Task.defer

paualarco avatar Sep 29 '22 20:09 paualarco

Yeah, my point was that fromFutureLike is a less error-prone API because it takes Task[F[A]].

rfkm avatar Sep 30 '22 04:09 rfkm