mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-08 09:23:50 +00:00
commit
30389e8536
@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.21.3
|
||||||
|
|
||||||
|
* `Colors`:
|
||||||
|
* Added as a module. It should be used by default in case you wish all the API currently realized for `HEXAColor`
|
||||||
|
* `Coroutines`:
|
||||||
|
* Fix of [#374](https://github.com/InsanusMokrassar/MicroUtils/issues/374):
|
||||||
|
* Add vararg variants of `awaitFirst`
|
||||||
|
* Add `joinFirst`
|
||||||
|
|
||||||
## 0.21.2
|
## 0.21.2
|
||||||
|
|
||||||
* `KSP`:
|
* `KSP`:
|
||||||
|
17
colors/build.gradle
Normal file
17
colors/build.gradle
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api project(":micro_utils.colors.common")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
298
colors/src/commonMain/kotlin/StandardColors.kt
Normal file
298
colors/src/commonMain/kotlin/StandardColors.kt
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
package dev.inmo.micro_utils.colors
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.colors.common.HEXAColor
|
||||||
|
|
||||||
|
val HEXAColor.Companion.aliceblue
|
||||||
|
get() = HEXAColor(0xF0F8FFFFu)
|
||||||
|
val HEXAColor.Companion.antiquewhite
|
||||||
|
get() = HEXAColor(0xFAEBD7FFu)
|
||||||
|
val HEXAColor.Companion.aqua
|
||||||
|
get() = HEXAColor(0x00FFFFFFu)
|
||||||
|
val HEXAColor.Companion.aquamarine
|
||||||
|
get() = HEXAColor(0x7FFFD4FFu)
|
||||||
|
val HEXAColor.Companion.azure
|
||||||
|
get() = HEXAColor(0xF0FFFFFFu)
|
||||||
|
val HEXAColor.Companion.beige
|
||||||
|
get() = HEXAColor(0xF5F5DCFFu)
|
||||||
|
val HEXAColor.Companion.bisque
|
||||||
|
get() = HEXAColor(0xFFE4C4FFu)
|
||||||
|
val HEXAColor.Companion.black
|
||||||
|
get() = HEXAColor(0x000000FFu)
|
||||||
|
val HEXAColor.Companion.blanchedalmond
|
||||||
|
get() = HEXAColor(0xFFEBCDFFu)
|
||||||
|
val HEXAColor.Companion.blue
|
||||||
|
get() = HEXAColor(0x0000FFFFu)
|
||||||
|
val HEXAColor.Companion.blueviolet
|
||||||
|
get() = HEXAColor(0x8A2BE2FFu)
|
||||||
|
val HEXAColor.Companion.brown
|
||||||
|
get() = HEXAColor(0xA52A2AFFu)
|
||||||
|
val HEXAColor.Companion.burlywood
|
||||||
|
get() = HEXAColor(0xDEB887FFu)
|
||||||
|
val HEXAColor.Companion.cadetblue
|
||||||
|
get() = HEXAColor(0x5F9EA0FFu)
|
||||||
|
val HEXAColor.Companion.chartreuse
|
||||||
|
get() = HEXAColor(0x7FFF00FFu)
|
||||||
|
val HEXAColor.Companion.chocolate
|
||||||
|
get() = HEXAColor(0xD2691EFFu)
|
||||||
|
val HEXAColor.Companion.coral
|
||||||
|
get() = HEXAColor(0xFF7F50FFu)
|
||||||
|
val HEXAColor.Companion.cornflowerblue
|
||||||
|
get() = HEXAColor(0x6495EDFFu)
|
||||||
|
val HEXAColor.Companion.cornsilk
|
||||||
|
get() = HEXAColor(0xFFF8DCFFu)
|
||||||
|
val HEXAColor.Companion.crimson
|
||||||
|
get() = HEXAColor(0xDC143CFFu)
|
||||||
|
val HEXAColor.Companion.cyan
|
||||||
|
get() = HEXAColor(0x00FFFFFFu)
|
||||||
|
val HEXAColor.Companion.darkblue
|
||||||
|
get() = HEXAColor(0x00008BFFu)
|
||||||
|
val HEXAColor.Companion.darkcyan
|
||||||
|
get() = HEXAColor(0x008B8BFFu)
|
||||||
|
val HEXAColor.Companion.darkgoldenrod
|
||||||
|
get() = HEXAColor(0xB8860BFFu)
|
||||||
|
val HEXAColor.Companion.darkgray
|
||||||
|
get() = HEXAColor(0xA9A9A9FFu)
|
||||||
|
val HEXAColor.Companion.darkgreen
|
||||||
|
get() = HEXAColor(0x006400FFu)
|
||||||
|
val HEXAColor.Companion.darkgrey
|
||||||
|
get() = HEXAColor(0xA9A9A9FFu)
|
||||||
|
val HEXAColor.Companion.darkkhaki
|
||||||
|
get() = HEXAColor(0xBDB76BFFu)
|
||||||
|
val HEXAColor.Companion.darkmagenta
|
||||||
|
get() = HEXAColor(0x8B008BFFu)
|
||||||
|
val HEXAColor.Companion.darkolivegreen
|
||||||
|
get() = HEXAColor(0x556B2FFFu)
|
||||||
|
val HEXAColor.Companion.darkorange
|
||||||
|
get() = HEXAColor(0xFF8C00FFu)
|
||||||
|
val HEXAColor.Companion.darkorchid
|
||||||
|
get() = HEXAColor(0x9932CCFFu)
|
||||||
|
val HEXAColor.Companion.darkred
|
||||||
|
get() = HEXAColor(0x8B0000FFu)
|
||||||
|
val HEXAColor.Companion.darksalmon
|
||||||
|
get() = HEXAColor(0xE9967AFFu)
|
||||||
|
val HEXAColor.Companion.darkseagreen
|
||||||
|
get() = HEXAColor(0x8FBC8FFFu)
|
||||||
|
val HEXAColor.Companion.darkslateblue
|
||||||
|
get() = HEXAColor(0x483D8BFFu)
|
||||||
|
val HEXAColor.Companion.darkslategray
|
||||||
|
get() = HEXAColor(0x2F4F4FFFu)
|
||||||
|
val HEXAColor.Companion.darkslategrey
|
||||||
|
get() = HEXAColor(0x2F4F4FFFu)
|
||||||
|
val HEXAColor.Companion.darkturquoise
|
||||||
|
get() = HEXAColor(0x00CED1FFu)
|
||||||
|
val HEXAColor.Companion.darkviolet
|
||||||
|
get() = HEXAColor(0x9400D3FFu)
|
||||||
|
val HEXAColor.Companion.deeppink
|
||||||
|
get() = HEXAColor(0xFF1493FFu)
|
||||||
|
val HEXAColor.Companion.deepskyblue
|
||||||
|
get() = HEXAColor(0x00BFFFFFu)
|
||||||
|
val HEXAColor.Companion.dimgray
|
||||||
|
get() = HEXAColor(0x696969FFu)
|
||||||
|
val HEXAColor.Companion.dimgrey
|
||||||
|
get() = HEXAColor(0x696969FFu)
|
||||||
|
val HEXAColor.Companion.dodgerblue
|
||||||
|
get() = HEXAColor(0x1E90FFFFu)
|
||||||
|
val HEXAColor.Companion.firebrick
|
||||||
|
get() = HEXAColor(0xB22222FFu)
|
||||||
|
val HEXAColor.Companion.floralwhite
|
||||||
|
get() = HEXAColor(0xFFFAF0FFu)
|
||||||
|
val HEXAColor.Companion.forestgreen
|
||||||
|
get() = HEXAColor(0x228B22FFu)
|
||||||
|
val HEXAColor.Companion.fuchsia
|
||||||
|
get() = HEXAColor(0xFF00FFFFu)
|
||||||
|
val HEXAColor.Companion.gainsboro
|
||||||
|
get() = HEXAColor(0xDCDCDCFFu)
|
||||||
|
val HEXAColor.Companion.ghostwhite
|
||||||
|
get() = HEXAColor(0xF8F8FFFFu)
|
||||||
|
val HEXAColor.Companion.gold
|
||||||
|
get() = HEXAColor(0xFFD700FFu)
|
||||||
|
val HEXAColor.Companion.goldenrod
|
||||||
|
get() = HEXAColor(0xDAA520FFu)
|
||||||
|
val HEXAColor.Companion.gray
|
||||||
|
get() = HEXAColor(0x808080FFu)
|
||||||
|
val HEXAColor.Companion.green
|
||||||
|
get() = HEXAColor(0x008000FFu)
|
||||||
|
val HEXAColor.Companion.greenyellow
|
||||||
|
get() = HEXAColor(0xADFF2FFFu)
|
||||||
|
val HEXAColor.Companion.grey
|
||||||
|
get() = HEXAColor(0x808080FFu)
|
||||||
|
val HEXAColor.Companion.honeydew
|
||||||
|
get() = HEXAColor(0xF0FFF0FFu)
|
||||||
|
val HEXAColor.Companion.hotpink
|
||||||
|
get() = HEXAColor(0xFF69B4FFu)
|
||||||
|
val HEXAColor.Companion.indianred
|
||||||
|
get() = HEXAColor(0xCD5C5CFFu)
|
||||||
|
val HEXAColor.Companion.indigo
|
||||||
|
get() = HEXAColor(0x4B0082FFu)
|
||||||
|
val HEXAColor.Companion.ivory
|
||||||
|
get() = HEXAColor(0xFFFFF0FFu)
|
||||||
|
val HEXAColor.Companion.khaki
|
||||||
|
get() = HEXAColor(0xF0E68CFFu)
|
||||||
|
val HEXAColor.Companion.lavender
|
||||||
|
get() = HEXAColor(0xE6E6FAFFu)
|
||||||
|
val HEXAColor.Companion.lavenderblush
|
||||||
|
get() = HEXAColor(0xFFF0F5FFu)
|
||||||
|
val HEXAColor.Companion.lawngreen
|
||||||
|
get() = HEXAColor(0x7CFC00FFu)
|
||||||
|
val HEXAColor.Companion.lemonchiffon
|
||||||
|
get() = HEXAColor(0xFFFACDFFu)
|
||||||
|
val HEXAColor.Companion.lightblue
|
||||||
|
get() = HEXAColor(0xADD8E6FFu)
|
||||||
|
val HEXAColor.Companion.lightcoral
|
||||||
|
get() = HEXAColor(0xF08080FFu)
|
||||||
|
val HEXAColor.Companion.lightcyan
|
||||||
|
get() = HEXAColor(0xE0FFFFFFu)
|
||||||
|
val HEXAColor.Companion.lightgoldenrodyellow
|
||||||
|
get() = HEXAColor(0xFAFAD2FFu)
|
||||||
|
val HEXAColor.Companion.lightgray
|
||||||
|
get() = HEXAColor(0xD3D3D3FFu)
|
||||||
|
val HEXAColor.Companion.lightgreen
|
||||||
|
get() = HEXAColor(0x90EE90FFu)
|
||||||
|
val HEXAColor.Companion.lightgrey
|
||||||
|
get() = HEXAColor(0xD3D3D3FFu)
|
||||||
|
val HEXAColor.Companion.lightpink
|
||||||
|
get() = HEXAColor(0xFFB6C1FFu)
|
||||||
|
val HEXAColor.Companion.lightsalmon
|
||||||
|
get() = HEXAColor(0xFFA07AFFu)
|
||||||
|
val HEXAColor.Companion.lightseagreen
|
||||||
|
get() = HEXAColor(0x20B2AAFFu)
|
||||||
|
val HEXAColor.Companion.lightskyblue
|
||||||
|
get() = HEXAColor(0x87CEFAFFu)
|
||||||
|
val HEXAColor.Companion.lightslategray
|
||||||
|
get() = HEXAColor(0x778899FFu)
|
||||||
|
val HEXAColor.Companion.lightslategrey
|
||||||
|
get() = HEXAColor(0x778899FFu)
|
||||||
|
val HEXAColor.Companion.lightsteelblue
|
||||||
|
get() = HEXAColor(0xB0C4DEFFu)
|
||||||
|
val HEXAColor.Companion.lightyellow
|
||||||
|
get() = HEXAColor(0xFFFFE0FFu)
|
||||||
|
val HEXAColor.Companion.lime
|
||||||
|
get() = HEXAColor(0x00FF00FFu)
|
||||||
|
val HEXAColor.Companion.limegreen
|
||||||
|
get() = HEXAColor(0x32CD32FFu)
|
||||||
|
val HEXAColor.Companion.linen
|
||||||
|
get() = HEXAColor(0xFAF0E6FFu)
|
||||||
|
val HEXAColor.Companion.magenta
|
||||||
|
get() = HEXAColor(0xFF00FFFFu)
|
||||||
|
val HEXAColor.Companion.maroon
|
||||||
|
get() = HEXAColor(0x800000FFu)
|
||||||
|
val HEXAColor.Companion.mediumaquamarine
|
||||||
|
get() = HEXAColor(0x66CDAAFFu)
|
||||||
|
val HEXAColor.Companion.mediumblue
|
||||||
|
get() = HEXAColor(0x0000CDFFu)
|
||||||
|
val HEXAColor.Companion.mediumorchid
|
||||||
|
get() = HEXAColor(0xBA55D3FFu)
|
||||||
|
val HEXAColor.Companion.mediumpurple
|
||||||
|
get() = HEXAColor(0x9370DBFFu)
|
||||||
|
val HEXAColor.Companion.mediumseagreen
|
||||||
|
get() = HEXAColor(0x3CB371FFu)
|
||||||
|
val HEXAColor.Companion.mediumslateblue
|
||||||
|
get() = HEXAColor(0x7B68EEFFu)
|
||||||
|
val HEXAColor.Companion.mediumspringgreen
|
||||||
|
get() = HEXAColor(0x00FA9AFFu)
|
||||||
|
val HEXAColor.Companion.mediumturquoise
|
||||||
|
get() = HEXAColor(0x48D1CCFFu)
|
||||||
|
val HEXAColor.Companion.mediumvioletred
|
||||||
|
get() = HEXAColor(0xC71585FFu)
|
||||||
|
val HEXAColor.Companion.midnightblue
|
||||||
|
get() = HEXAColor(0x191970FFu)
|
||||||
|
val HEXAColor.Companion.mintcream
|
||||||
|
get() = HEXAColor(0xF5FFFAFFu)
|
||||||
|
val HEXAColor.Companion.mistyrose
|
||||||
|
get() = HEXAColor(0xFFE4E1FFu)
|
||||||
|
val HEXAColor.Companion.moccasin
|
||||||
|
get() = HEXAColor(0xFFE4B5FFu)
|
||||||
|
val HEXAColor.Companion.navajowhite
|
||||||
|
get() = HEXAColor(0xFFDEADFFu)
|
||||||
|
val HEXAColor.Companion.navy
|
||||||
|
get() = HEXAColor(0x000080FFu)
|
||||||
|
val HEXAColor.Companion.oldlace
|
||||||
|
get() = HEXAColor(0xFDF5E6FFu)
|
||||||
|
val HEXAColor.Companion.olive
|
||||||
|
get() = HEXAColor(0x808000FFu)
|
||||||
|
val HEXAColor.Companion.olivedrab
|
||||||
|
get() = HEXAColor(0x6B8E23FFu)
|
||||||
|
val HEXAColor.Companion.orange
|
||||||
|
get() = HEXAColor(0xFFA500FFu)
|
||||||
|
val HEXAColor.Companion.orangered
|
||||||
|
get() = HEXAColor(0xFF4500FFu)
|
||||||
|
val HEXAColor.Companion.orchid
|
||||||
|
get() = HEXAColor(0xDA70D6FFu)
|
||||||
|
val HEXAColor.Companion.palegoldenrod
|
||||||
|
get() = HEXAColor(0xEEE8AAFFu)
|
||||||
|
val HEXAColor.Companion.palegreen
|
||||||
|
get() = HEXAColor(0x98FB98FFu)
|
||||||
|
val HEXAColor.Companion.paleturquoise
|
||||||
|
get() = HEXAColor(0xAFEEEEFFu)
|
||||||
|
val HEXAColor.Companion.palevioletred
|
||||||
|
get() = HEXAColor(0xDB7093FFu)
|
||||||
|
val HEXAColor.Companion.papayawhip
|
||||||
|
get() = HEXAColor(0xFFEFD5FFu)
|
||||||
|
val HEXAColor.Companion.peachpuff
|
||||||
|
get() = HEXAColor(0xFFDAB9FFu)
|
||||||
|
val HEXAColor.Companion.peru
|
||||||
|
get() = HEXAColor(0xCD853FFFu)
|
||||||
|
val HEXAColor.Companion.pink
|
||||||
|
get() = HEXAColor(0xFFC0CBFFu)
|
||||||
|
val HEXAColor.Companion.plum
|
||||||
|
get() = HEXAColor(0xDDA0DDFFu)
|
||||||
|
val HEXAColor.Companion.powderblue
|
||||||
|
get() = HEXAColor(0xB0E0E6FFu)
|
||||||
|
val HEXAColor.Companion.purple
|
||||||
|
get() = HEXAColor(0x800080FFu)
|
||||||
|
val HEXAColor.Companion.red
|
||||||
|
get() = HEXAColor(0xFF0000FFu)
|
||||||
|
val HEXAColor.Companion.rosybrown
|
||||||
|
get() = HEXAColor(0xBC8F8FFFu)
|
||||||
|
val HEXAColor.Companion.royalblue
|
||||||
|
get() = HEXAColor(0x4169E1FFu)
|
||||||
|
val HEXAColor.Companion.saddlebrown
|
||||||
|
get() = HEXAColor(0x8B4513FFu)
|
||||||
|
val HEXAColor.Companion.salmon
|
||||||
|
get() = HEXAColor(0xFA8072FFu)
|
||||||
|
val HEXAColor.Companion.sandybrown
|
||||||
|
get() = HEXAColor(0xF4A460FFu)
|
||||||
|
val HEXAColor.Companion.seagreen
|
||||||
|
get() = HEXAColor(0x2E8B57FFu)
|
||||||
|
val HEXAColor.Companion.seashell
|
||||||
|
get() = HEXAColor(0xFFF5EEFFu)
|
||||||
|
val HEXAColor.Companion.sienna
|
||||||
|
get() = HEXAColor(0xA0522DFFu)
|
||||||
|
val HEXAColor.Companion.silver
|
||||||
|
get() = HEXAColor(0xC0C0C0FFu)
|
||||||
|
val HEXAColor.Companion.skyblue
|
||||||
|
get() = HEXAColor(0x87CEEBFFu)
|
||||||
|
val HEXAColor.Companion.slateblue
|
||||||
|
get() = HEXAColor(0x6A5ACDFFu)
|
||||||
|
val HEXAColor.Companion.slategray
|
||||||
|
get() = HEXAColor(0x708090FFu)
|
||||||
|
val HEXAColor.Companion.slategrey
|
||||||
|
get() = HEXAColor(0x708090FFu)
|
||||||
|
val HEXAColor.Companion.snow
|
||||||
|
get() = HEXAColor(0xFFFAFAFFu)
|
||||||
|
val HEXAColor.Companion.springgreen
|
||||||
|
get() = HEXAColor(0x00FF7FFFu)
|
||||||
|
val HEXAColor.Companion.steelblue
|
||||||
|
get() = HEXAColor(0x4682B4FFu)
|
||||||
|
val HEXAColor.Companion.tan
|
||||||
|
get() = HEXAColor(0xD2B48CFFu)
|
||||||
|
val HEXAColor.Companion.teal
|
||||||
|
get() = HEXAColor(0x008080FFu)
|
||||||
|
val HEXAColor.Companion.thistle
|
||||||
|
get() = HEXAColor(0xD8BFD8FFu)
|
||||||
|
val HEXAColor.Companion.tomato
|
||||||
|
get() = HEXAColor(0xFF6347FFu)
|
||||||
|
val HEXAColor.Companion.turquoise
|
||||||
|
get() = HEXAColor(0x40E0D0FFu)
|
||||||
|
val HEXAColor.Companion.violet
|
||||||
|
get() = HEXAColor(0xEE82EEFFu)
|
||||||
|
val HEXAColor.Companion.wheat
|
||||||
|
get() = HEXAColor(0xF5DEB3FFu)
|
||||||
|
val HEXAColor.Companion.white
|
||||||
|
get() = HEXAColor(0xFFFFFFFFu)
|
||||||
|
val HEXAColor.Companion.whitesmoke
|
||||||
|
get() = HEXAColor(0xF5F5F5FFu)
|
||||||
|
val HEXAColor.Companion.yellow
|
||||||
|
get() = HEXAColor(0xFFFF00FFu)
|
||||||
|
val HEXAColor.Companion.yellowgreen
|
||||||
|
get() = HEXAColor(0x9ACD32FFu)
|
@ -3,6 +3,12 @@ package dev.inmo.micro_utils.coroutines
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Deferred.await] on all [this] [Deferred]s. The first [Deferred] completed its work will interrupt all
|
||||||
|
* others awaits and, if [cancelOnResult] passed as true (**by default**), will also cancel all the others [Deferred]s
|
||||||
|
*
|
||||||
|
* @param scope Will be used to create [CoroutineScope.LinkedSupervisorScope] and launch joining of all [Job]s in it
|
||||||
|
*/
|
||||||
suspend fun <T> Iterable<Deferred<T>>.awaitFirstWithDeferred(
|
suspend fun <T> Iterable<Deferred<T>>.awaitFirstWithDeferred(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
cancelOnResult: Boolean = true
|
cancelOnResult: Boolean = true
|
||||||
@ -24,10 +30,45 @@ suspend fun <T> Iterable<Deferred<T>>.awaitFirstWithDeferred(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Deferred.await] on all [this] [Deferred]s. The first [Deferred] completed its work will interrupt all
|
||||||
|
* others awaits and, if [cancelOnResult] passed as true (**by default**), will also cancel all the others [Deferred]s
|
||||||
|
*
|
||||||
|
* @param scope Will be used to create [CoroutineScope.LinkedSupervisorScope] and launch joining of all [Job]s in it
|
||||||
|
*/
|
||||||
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(
|
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
cancelOnResult: Boolean = true
|
cancelOnResult: Boolean = true
|
||||||
): T = awaitFirstWithDeferred(scope, cancelOnResult).second
|
): T = awaitFirstWithDeferred(scope, cancelOnResult).second
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Deferred.await] on all [this] [Deferred]s. The first [Deferred] completed its work will interrupt all
|
||||||
|
* others awaits and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [Deferred]s
|
||||||
|
*
|
||||||
|
* Creates [CoroutineScope] using [coroutineContext] for internal purposes
|
||||||
|
*/
|
||||||
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(
|
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(
|
||||||
cancelOthers: Boolean = true
|
cancelOthers: Boolean = true
|
||||||
): T = awaitFirst(CoroutineScope(coroutineContext), cancelOthers)
|
): T = awaitFirst(CoroutineScope(coroutineContext), cancelOthers)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Deferred.await] on all [deferreds]. The first [Deferred] completed its work will interrupt all
|
||||||
|
* others awaits and, if [cancelOnResult] passed as true (**by default**), will also cancel all the others [deferreds]
|
||||||
|
*
|
||||||
|
* @param scope Will be used to create [CoroutineScope.LinkedSupervisorScope] and launch joining of all [Job]s in it
|
||||||
|
*/
|
||||||
|
suspend fun <T> awaitFirst(
|
||||||
|
vararg deferreds: Deferred<T>,
|
||||||
|
scope: CoroutineScope,
|
||||||
|
cancelOnResult: Boolean = true
|
||||||
|
): T = deferreds.toList().awaitFirstWithDeferred(scope, cancelOnResult).second
|
||||||
|
/**
|
||||||
|
* Trying to [Deferred.await] on all [deferreds]. The first [Deferred] completed its work will interrupt all
|
||||||
|
* others awaits and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [deferreds]
|
||||||
|
*
|
||||||
|
* Creates [CoroutineScope] using [coroutineContext] for internal purposes
|
||||||
|
*/
|
||||||
|
suspend fun <T> awaitFirst(
|
||||||
|
vararg deferreds: Deferred<T>,
|
||||||
|
cancelOthers: Boolean = true
|
||||||
|
): T = awaitFirst(*deferreds, scope = CoroutineScope(coroutineContext), cancelOnResult = cancelOthers)
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Job.join] on all [this] [Job]s. The first [Job] completed its work will interrupt all others joins
|
||||||
|
* and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [Job]s
|
||||||
|
*
|
||||||
|
* @param scope Will be used to create [CoroutineScope.LinkedSupervisorScope] and launch joining of all [Job]s in it
|
||||||
|
*/
|
||||||
|
suspend fun Iterable<Job>.joinFirst(
|
||||||
|
scope: CoroutineScope,
|
||||||
|
cancelOthers: Boolean = true
|
||||||
|
): Job {
|
||||||
|
val resultDeferred = CompletableDeferred<Job>()
|
||||||
|
val scope = scope.LinkedSupervisorScope()
|
||||||
|
forEach {
|
||||||
|
scope.launch {
|
||||||
|
it.join()
|
||||||
|
resultDeferred.complete(it)
|
||||||
|
scope.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultDeferred.await().also {
|
||||||
|
if (cancelOthers) {
|
||||||
|
forEach {
|
||||||
|
runCatchingSafely { it.cancel() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Trying to [Job.join] on all [this] [Job]s. The first [Job] completed its work will interrupt all others joins
|
||||||
|
* and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [Job]s
|
||||||
|
*
|
||||||
|
* Creates [CoroutineScope] using [coroutineContext] for internal purposes
|
||||||
|
*/
|
||||||
|
suspend fun Iterable<Job>.joinFirst(
|
||||||
|
cancelOthers: Boolean = true
|
||||||
|
): Job = joinFirst(CoroutineScope(coroutineContext), cancelOthers)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Job.join] on all [jobs]. The first [Job] completed its work will interrupt all others joins
|
||||||
|
* and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [Job]s
|
||||||
|
*
|
||||||
|
* @param scope Will be used to create [CoroutineScope.LinkedSupervisorScope] and launch joining of all [Job]s in it
|
||||||
|
*/
|
||||||
|
suspend fun joinFirst(
|
||||||
|
vararg jobs: Job,
|
||||||
|
scope: CoroutineScope,
|
||||||
|
cancelOthers: Boolean = true
|
||||||
|
): Job = jobs.toList().joinFirst(scope, cancelOthers)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to [Job.join] on all [jobs]. The first [Job] completed its work will interrupt all others joins
|
||||||
|
* and, if [cancelOthers] passed as true (**by default**), will also cancel all the others [Job]s
|
||||||
|
*
|
||||||
|
* Creates [CoroutineScope] using [coroutineContext] for internal purposes
|
||||||
|
*/
|
||||||
|
suspend fun joinFirst(
|
||||||
|
vararg jobs: Job,
|
||||||
|
cancelOthers: Boolean = true
|
||||||
|
): Job = joinFirst(*jobs, scope = CoroutineScope(coroutineContext), cancelOthers = cancelOthers)
|
@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.21.2
|
version=0.21.3
|
||||||
android_code_version=261
|
android_code_version=262
|
||||||
|
@ -42,6 +42,8 @@ String[] includes = [
|
|||||||
":serialization:mapper",
|
":serialization:mapper",
|
||||||
":startup:plugin",
|
":startup:plugin",
|
||||||
":startup:launcher",
|
":startup:launcher",
|
||||||
|
|
||||||
|
":colors",
|
||||||
":colors:common",
|
":colors:common",
|
||||||
|
|
||||||
":resources",
|
":resources",
|
||||||
|
Loading…
Reference in New Issue
Block a user