-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: #48
- Loading branch information
Nikolay Kochetkov
committed
Sep 29, 2023
1 parent
215ccc5
commit 7a672d4
Showing
5 changed files
with
41 additions
and
6 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
15 changes: 15 additions & 0 deletions
15
coroutines/src/commonMain/kotlin/com/motorro/rxlcemodel/coroutines/coroutines.kt
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,15 @@ | ||
import kotlinx.coroutines.CancellationException | ||
|
||
/** | ||
* Calls the specified function [block] with `this` value as its receiver and returns its encapsulated result if invocation was successful, | ||
* catching any [Throwable] exception besides [CancellationException] that was thrown from the [block] function execution and encapsulating it as a failure. | ||
*/ | ||
public inline fun <T, R> T.coroutinesRunCatching(block: T.() -> R): Result<R> { | ||
return try { | ||
Result.success(block()) | ||
} catch (c: CancellationException) { | ||
throw c | ||
} catch (e: Throwable) { | ||
Result.failure(e) | ||
} | ||
} |
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