Skip to content

Commit

Permalink
[monix] scaladocs (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil authored Dec 4, 2024
1 parent 5d5f0c7 commit 9c7d3e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
34 changes: 34 additions & 0 deletions kyo-monix/shared/src/main/scala/kyo/Monix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,28 @@ package kyo
import kyo.*
import monix.eval.Task

/** Integration between Kyo and Monix Task. Provides bidirectional conversion between Kyo's effect system and Monix Task, enabling seamless
* interop between the two libraries.
*
* The implementation handles proper resource management and cancellation semantics. Task cancellation is propagated to Kyo fibers, while
* Kyo fiber interruption triggers Task cancellation. Error handling is preserved across boundaries and asynchronous boundaries are
* properly managed.
*/
object Monix:

/** Converts a Monix Task into a Kyo computation. The resulting computation captures both asynchronous execution and potential failure
* through Abort and Async.
*
* The implementation ensures proper cancellation handling if the Kyo fiber is interrupted, error propagation from Task failures to Kyo
* Abort, and resource cleanup on cancellation.
*
* @param task
* The Monix Task to convert
* @param scheduler
* The Monix scheduler for Task execution
* @return
* A Kyo computation combining Abort and Async that represents the Task execution
*/
def get[A: Flat](task: Task[A])(using monix.execution.Scheduler, Frame): A < (Abort[Throwable] & Async) =
IO.Unsafe {
val p = Promise.Unsafe.init[Throwable, A]()
Expand All @@ -15,6 +35,20 @@ object Monix:
p.safe.get
}

/** Converts a Kyo computation into a Monix Task. The resulting Task will execute the computation with proper handling of cancellation
* and errors.
*
* Note that this method only accepts computations with Abort[Throwable] and Async. To convert computations with additional
* capabilities, first handle those capabilities to reduce to just Abort[Throwable] and Async before calling this method.
*
* The implementation ensures Task cancellation propagates to the underlying Kyo fiber, Kyo failures are converted to Task failures,
* and resources are properly cleaned up on cancellation.
*
* @param v
* The Kyo computation to convert, requires only Abort[Throwable] and Async
* @return
* A Monix Task representing the computation execution
*/
def run[A: Flat](v: => A < (Abort[Throwable] & Async))(using f: Frame): Task[A] =
Task.cancelable { cb =>
import AllowUnsafe.embrace.danger
Expand Down
5 changes: 0 additions & 5 deletions kyo-stm/shared/src/main/scala/kyo/TRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import scala.annotation.tailrec

/** A transactional reference that can be modified within STM transactions. Provides atomic read and write operations with strong
* consistency guarantees.
*
* @param id
* Unique identifier for this reference
* @param state
* The current state of the reference
*/
sealed trait TRef[A]:

Expand Down

0 comments on commit 9c7d3e7

Please sign in to comment.