-
Couldn't load subscription status.
- Fork 1.4k
ZIO.fromPromise operator #4165
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
ZIO.fromPromise operator #4165
Conversation
|
In this PR there're also some code from a previous PR (#4163) that is pending to being merged once @adamgfraser approve it |
|
@politrons Can't the use case of lazy evaluation be addressed by If we want something just for interop I think we would want it to just take a |
|
@adamgfraser Hi again, If I understand your comment, I just extract the logic of execution and completing the promise out of the operator. So basically we just extract the future from the promise. Not sure to be honest if now this is a useful operator. |
| * Imports a [[scala.concurrent.Promise]] we generate a future from promise, | ||
| * and we pass to [fromFuture] to transform into ZIO[Any, Throwable, A] | ||
| */ | ||
| def fromPromiseScala[A, B](promise: scala.concurrent.Promise[A]): ZIO[Any, Throwable, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the B type parameter here and return a Task[A].
|
@politrons Hey! 😃 Yes I think so. That gives the caller the flexibility to complete the promise where they want to. If this is being used for interoperability the code that completes the promise may be impure and in another part of the application where it may not be possible to just import it into the ZIO runtime. |
|
Can you merge upstream changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to delete the old tests from StackTracesSpec, right? Otherwise looks great!
|
@adamgfraser I already delete those test when I moved to ZIOSpec |
|
@politrons Looks like the ones from when we added getOrFailOption are still there unless I am looking at the wrong version? |
|
@adamgfraser I made in this commit ee7d8f4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!
|
you welcome, thanks again for the support |
I don't know if this operator it has any sense in the ZIO ecosystem, I know we can achieve the same goal of lazy evaluation of futures using fibers. But maybe is not a bad alternative, to provide an operator just like
fromFuture, butfromPromiseas inter-opt operator for those scala developers, that want to usepromisesfor lazy evaluation of futures.Description:
Imports a [[scala.concurrent.Promise[A]] an input value of B and a function to apply in [complete] function of promise.
We complete the promise in another thread avoiding blocking the function execution, and in the main thread we generate a future from promise, and we pass to [fromFuture] to transform into ZIO[Any, Throwable, A].
With this operator we allow use Scala promise to have a lazy evaluation of the logic that it will be executed in another thread only when the whole program is evaluated.