-
Notifications
You must be signed in to change notification settings - Fork 449
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
Arrow Fx DSL #3443
base: main
Are you sure you want to change the base?
Arrow Fx DSL #3443
Conversation
One DSL to rule them all and in the coroutines bind them? |
"It all began with the forging of the Great" DSLs 🤣 |
These can also come after 2.0.0 @serras |
} catch (e: Throwable) { | ||
throw e | ||
} | ||
override fun autoClose(close: (Throwable?) -> Unit) = |
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.
Nit: I'd like onClose
better to reflect onRelease
from ResourceScope
*/ | ||
// TODO should this be implemented on ScopingScope | ||
// Or should ScopingScope be used to implement a separate SagaScope?? | ||
public suspend fun <A> ScopingScope.saga( |
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.
Isn't this just ScopingScope.resource
?
import kotlinx.coroutines.withContext | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
public interface ScopingScope : AutoCloseScope { |
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.
This is identical to ResourceScope
, no? ScopingScope
doesn't feel like a better name IMO.
|
||
public interface ScopingScope : AutoCloseScope { | ||
public override fun autoClose(close: (Throwable?) -> Unit): Unit | ||
public fun closing(block: suspend (Throwable?) -> Unit): Unit |
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.
Similarly, calling this onRelease
might make for a more seamless transition.
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
public interface ScopingScope : AutoCloseScope { | ||
public override fun autoClose(close: (Throwable?) -> Unit): Unit |
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.
this can have a default impl of: closing { close(it) }
Hey @nomisRev! Turns out I've accidentally reinvented some of your |
This PR proposes a new module for Arrow Fx Coroutines, which covers the existing behavior in Arrow Fx but in a generalised way using DSLs.
parMapN
is covered byAwaitAllScope
Resource
already was a DSL,Scoped
offers a similar but more lightweight DSL (noExitCase
), and simplified SAM.raceN
will be covered byRacingScope
(Upgrading from 1.1.3 til 1.1.4 (and higher) breaks getOrElse: List<String> turns into List<Serializable> #3342)parZipOrAccumulate
should be covered by a combination ofAwaitAllScope
& `Accumulating)All the above non-DSL variants, can be implemented by their DSL variations. Simplifying the internals of Arrow Fx Coroutines. The idea behind this is future proofing, since my ambition for 3.0 is to split
Raise
and the typed error handling DSL fromArrow Core
such that users can rely on only the DSL after 3.0. That should be do-able with only a single binary breakage in Arrow Core, so 3.0 should be source compatible, and 99% binary compatible once Context Parameters are released.AwaitAllScope
parZipOrAccumulate
DSLRacingScope
Investigate if we need, or want,
<E>
variants when insideRaise<E>
.