Hey :slightly_smiling_face: I have a question abou...
# arrow
m
Hey ๐Ÿ™‚ I have a question about the saga-pattern implementation of arrow (https://arrow-kt.io/learn/resilience/saga/). Does it only work for exceptions, or can a saga action also use the raise-dsl or other forms or typed error handling? Looking at the implementation (https://github.com/arrow-kt/arrow/blob/main/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt) Iโ€™d assume it only works for actions throwing exceptions in case of a failure, but I may also be wrong ๐Ÿ™‚
s
It works with Raise! All DSL from Arrow do! Including cancellation on Arrow Fx Coroutines, Saga, Resource, AutoClose, etc. Small example:
Copy code
either {
  saga {
    saga({ println("Action A") }) { println("Rollback A") }
    raise("failed")
    1
  }.transact()
}
There is however a big difference between
either { saga { } }
or
saga { either { } }
. The first is a computation that can fail with
E
, which inside is using a
saga
. Since
Saga
sees
raise
as a failure, it will rollback action A. In the latter case, we have a
Saga
that computes an
Either
. So any
Left.bind
, or
raise
, that is encountered will not fail the
Saga
but would return
Either.Left
if
transact
is called on the
Saga
. Hope that helps! I think we should probably add this example to the documentation โ˜บ๏ธ I find it really neat that all DSLs can be nested, and that depending on the order you can get different behavior.
๐Ÿ‘ 1
m
Thanks for the detailed explanation! IMO it would be helpful to explain that in the documentation as well, but it might also be just me ๐Ÿ™‚ > I find it really neat that all DSLs can be nested, and that depending on the order you can get different behavior. ๐Ÿ‘ - similar to how it is with
parMap, ...
s
Yes, I've been meaning to add it website for a while.. ๐Ÿ˜•
m
FYI: It works like a charm and I love it ๐Ÿ˜„
๐Ÿ™Œ 1
s
Awesome, happy to hear! arrow intensifies