-
Notifications
You must be signed in to change notification settings - Fork 450
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
AutoClose and Resource rehaul/cleanup #3431
Changes from all commits
1ff7f5f
a1303b6
4bf201e
49ec9fc
04103e8
b15e29a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package arrow | ||
|
||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
@PublishedApi | ||
internal actual fun Throwable.throwIfFatal(): Throwable = | ||
when(this) { | ||
is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError, is CancellationException -> throw this | ||
is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> throw this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hate that this function cannot be private. I really do not want to expose it 😓 This is why I had the |
||
else -> this | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,26 @@ import kotlinx.coroutines.CancellationException | |
import kotlinx.coroutines.NonCancellable | ||
import kotlinx.coroutines.withContext | ||
|
||
public sealed class ExitCase { | ||
public object Completed : ExitCase() { | ||
override fun toString(): String = | ||
"ExitCase.Completed" | ||
} | ||
|
||
public data class Cancelled(val exception: CancellationException) : ExitCase() | ||
public data class Failure(val failure: Throwable) : ExitCase() | ||
public sealed interface ExitCase { | ||
public data object Completed : ExitCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public data class Cancelled(val exception: CancellationException) : ExitCase | ||
public data class Failure(val failure: Throwable) : ExitCase | ||
|
||
public companion object { | ||
public fun ExitCase(error: Throwable): ExitCase = | ||
if (error is CancellationException) Cancelled(error) else Failure(error) | ||
public fun ExitCase(error: Throwable?): ExitCase = when (error) { | ||
null -> Completed | ||
is CancellationException -> Cancelled(error) | ||
else -> Failure(error) | ||
} | ||
} | ||
} | ||
|
||
public val ExitCase.throwableOrNull: Throwable? get() = when (this) { | ||
ExitCase.Completed -> null | ||
is ExitCase.Cancelled -> exception | ||
is ExitCase.Failure -> failure | ||
} | ||
|
||
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we define this inside I also think |
||
/** | ||
* Registers an [onCancel] handler after [fa]. | ||
* [onCancel] is guaranteed to be called in case of cancellation, otherwise it's ignored. | ||
|
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.
Idem, this introduces a source breaking change, to support suspend in the
acquire
step. If that is needed, I think users should preferonClose
, orResource
instead.So I would prefer to revert this also.