-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added extensions to coroutine builders
- Loading branch information
Showing
7 changed files
with
72 additions
and
21 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
26 changes: 26 additions & 0 deletions
26
core/src/commonMain/kotlin/me/y9san9/aqueue/AQueueAsync.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,26 @@ | ||
package me.y9san9.aqueue | ||
|
||
import kotlinx.coroutines.* | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
/** | ||
* Launches [block] with fine-grained control over concurrency. | ||
* | ||
* @param scope The scope used to launch a coroutine | ||
* @param start The start mode used to launch a coroutine | ||
* @param key It is guaranteed that requests with the same [key] will be executed consecutively | ||
* @param context The context that is used to launch new coroutines. You may limit parallelism using context | ||
* @param block The action to perform | ||
*/ | ||
public fun <T> AQueue.async( | ||
scope: CoroutineScope, | ||
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
key: Any? = null, | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
block: suspend () -> T | ||
): Deferred<T> { | ||
return scope.async(start = start) { | ||
execute(key, context, block) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
core/src/commonMain/kotlin/me/y9san9/aqueue/AQueueLaunch.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,28 @@ | ||
package me.y9san9.aqueue | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.CoroutineStart | ||
import kotlinx.coroutines.launch | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
/** | ||
* Launches [block] with fine-grained control over concurrency. | ||
* | ||
* @param scope The scope used to launch a coroutine | ||
* @param start The start mode used to launch a coroutine | ||
* @param key It is guaranteed that requests with the same [key] will be executed consecutively | ||
* @param context The context that is used to launch new coroutines. You may limit parallelism using context | ||
* @param block The action to perform | ||
*/ | ||
public fun AQueue.launch( | ||
scope: CoroutineScope, | ||
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
key: Any? = null, | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
block: suspend () -> Unit | ||
) { | ||
scope.launch(start = start) { | ||
execute(key, context, 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
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