-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refined implementation of #1022 (comment)
- Loading branch information
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package zio.kafka.utils | ||
|
||
import zio.{ IO, Promise, Trace, ZIO } | ||
|
||
/** | ||
* Less powerful interface than Promise | ||
* | ||
* Avoid leaking to the use the Promise methods we don't want him/her to have access to. | ||
*/ | ||
// noinspection ConvertExpressionToSAM | ||
trait Awaitable[E, A] { self => | ||
|
||
def await(implicit trace: Trace): IO[E, A] | ||
|
||
final def combineDiscard(other: Awaitable[E, _]): Awaitable[E, Unit] = | ||
new Awaitable[E, Unit] { | ||
override def await(implicit trace: Trace): IO[E, Unit] = | ||
for { | ||
_ <- self.await | ||
_ <- other.await | ||
} yield () | ||
} | ||
} | ||
|
||
//noinspection ConvertExpressionToSAM | ||
object Awaitable { | ||
def apply[E, A](p: Promise[E, A]): Awaitable[E, A] = | ||
new Awaitable[E, A] { | ||
override def await(implicit trace: Trace): IO[E, A] = p.await | ||
} | ||
|
||
val unit: Awaitable[Nothing, Unit] = | ||
new Awaitable[Nothing, Unit] { | ||
override def await(implicit trace: Trace): IO[Nothing, Unit] = ZIO.unit | ||
} | ||
} |