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

All APIs should be lazy #962

Open
rfkm opened this issue Sep 29, 2022 · 2 comments
Open

All APIs should be lazy #962

rfkm opened this issue Sep 29, 2022 · 2 comments

Comments

@rfkm
Copy link
Contributor

rfkm commented Sep 29, 2022

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.

def deleteObject(request: DeleteObjectRequest): Task[DeleteObjectResponse] =
Task.from(s3Client.deleteObject(request))

I think it is correct to use Task.fromFutureLike.

@paualarco
Copy link
Member

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

@rfkm
Copy link
Contributor Author

rfkm commented Sep 30, 2022

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

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

No branches or pull requests

2 participants