-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor public methods for plugins use
- Loading branch information
Showing
29 changed files
with
642 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
core/database/src/main/kotlin/com/flixclusive/core/database/util/FilmDataConverter.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
2 changes: 1 addition & 1 deletion
2
.../database/src/main/kotlin/com/flixclusive/core/database/util/WatchHistoryItemConverter.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
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
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
61 changes: 44 additions & 17 deletions
61
core/util/src/main/kotlin/com/flixclusive/core/util/coroutines/CoroutineHelper.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 |
---|---|---|
@@ -1,41 +1,68 @@ | ||
package com.flixclusive.core.util.coroutines | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withContext | ||
|
||
/** | ||
* | ||
* Fast list iteration: | ||
* https://www.linkedin.com/pulse/faster-list-iteration-using-kotlin-coroutines-elyes-mansour | ||
* | ||
* */ | ||
* Asynchronously maps the elements of the iterable using the specified suspending function [mapper]. | ||
* @param mapper The suspending function to apply to each element. | ||
* @return A list containing the results of applying the [mapper] function to each element. | ||
*/ | ||
suspend fun <T, R> Iterable<T>.mapAsync( | ||
mapper: suspend (T) -> R | ||
): List<R> = coroutineScope { map { async { mapper(it) } }.awaitAll() } | ||
|
||
/** | ||
* | ||
* Fast list iteration with index | ||
* */ | ||
* Asynchronously maps the elements of the iterable with their index using the specified suspending function [mapper]. | ||
* @param mapper The suspending function to apply to each indexed element. | ||
* @return A list containing the results of applying the [mapper] function to each indexed element. | ||
*/ | ||
suspend fun <T, R> Iterable<T>.mapIndexedAsync( | ||
mapper: suspend (Int, T) -> R | ||
): List<R> = coroutineScope { mapIndexed { i, item -> async { mapper(i, item) } }.awaitAll() } | ||
|
||
|
||
/** | ||
* | ||
* From Cloudstream `argamap`, aims to call | ||
* multiple suspend functions asynchronously | ||
* | ||
* https://github.com/recloudstream/cloudstream/blob/9d3b2ba3d2497e3a494f87b88b41687df7f5223a/app/src/main/java/com/lagradost/cloudstream3/ParCollections.kt#L76 | ||
* | ||
* */ | ||
* Executes multiple suspend functions asynchronously and waits for all to complete. | ||
* @param transforms The suspend functions to execute asynchronously. | ||
* @return A list containing the results of all the suspend functions. | ||
*/ | ||
fun <R> asyncCalls( | ||
vararg transforms: suspend () -> R, | ||
) = runBlocking { | ||
transforms.map { | ||
async { it.invoke() } | ||
}.awaitAll() | ||
} | ||
} | ||
|
||
private val ioCoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) | ||
|
||
|
||
/** | ||
* Launches a coroutine in the IO coroutine scope. | ||
* @param block The suspending lambda to execute in the IO coroutine scope. | ||
* @return A [Job] object representing the coroutine job. | ||
*/ | ||
fun ioLaunch(block: suspend () -> Unit): Job { | ||
return ioCoroutineScope.launch { | ||
block() | ||
} | ||
} | ||
|
||
/** | ||
* Calls the specified suspending function in the IO dispatcher. | ||
* @param block The suspending lambda to execute. | ||
* @return The result of the suspending function. | ||
*/ | ||
suspend fun <T> ioCall(block: suspend () -> T): T { | ||
return withContext(Dispatchers.IO) { | ||
block() | ||
} | ||
} |
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
8 changes: 0 additions & 8 deletions
8
core/util/src/main/kotlin/com/flixclusive/core/util/json/JsonHelper.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.