-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8f9fc
commit 83dcab5
Showing
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,5 @@ kotlin | |
iterable | ||
Guice | ||
GuiceInjectionService | ||
coroutine | ||
coroutines |
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,54 @@ | ||
# cloud-kotlin-coroutines-annotations | ||
|
||
This module adds coroutine support to [cloud-annotations](../annotations/index.md), allowing you to make | ||
the annotated command methods and suggestion providers suspending. | ||
|
||
The module also adds the ability to use Kotlin default values in both suspending and non-suspending methods. | ||
|
||
```kotlin title="Example of a suspending command method" | ||
@CommandMethod("command [argument]") | ||
suspend fun yourCommand( | ||
argument: String = "default value" | ||
): Unit = withContext(Dispatchers.IO) { | ||
// ... | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
Cloud is available through [Maven Central](https://search.maven.org/search?q=cloud.commandframework). | ||
|
||
<!-- prettier-ignore --> | ||
=== "Gradle (Kotlin)" | ||
|
||
```kotlin | ||
implementation("cloud.commandframework:cloud-kotlin-coroutines-annotations:2.0.0-SNAPSHOT") | ||
``` | ||
|
||
=== "Gradle (Groovy)" | ||
|
||
```groovy | ||
implementation 'cloud.commandframework:cloud-kotlin-coroutines-annotations:2.0.0-SNAPSHOT' | ||
``` | ||
|
||
You then need to install the `AnnotationParser` extension: | ||
|
||
```kotlin | ||
annotationParser.installCoroutineSupport() | ||
``` | ||
|
||
You may override the default coroutine scope (`GlobalScope`) and context (`EmptyCoroutineContext`) | ||
when invoking `installCoroutineSupport`. | ||
|
||
## Suggestion Providers | ||
|
||
The coroutine support extends the allowed signatures for `@Suggestions`-annotated methods, letting you return | ||
sequences of `Suggestion` objects as well as strings. | ||
|
||
```kotlin title="Example of a suspending suggestion provider" | ||
@Suggestions("custom-suggestions") | ||
suspend fun suggestionMethod( | ||
context: CommandContext<CommandSender>, | ||
input: String | ||
): Sequence<Suggestion> = sequenceOf("a", "b", "c").map(Suggestion::simple) | ||
``` |