Skip to content

Commit

Permalink
chore: add non .await syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
MagM1go committed Sep 18, 2024
1 parent 4313726 commit 80a1af7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/kotlin/top/boticord/BotiCordClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class BotiCordClient(
IllegalArgumentException::class,
SerializationException::class
)
private inline fun <reified T> decode(data: String) =
private inline fun <reified T> decode(data: String): T =
json.decodeFromString<T>(parseResultFromString(data))

@Throws(IllegalStateException::class)
Expand All @@ -110,6 +110,15 @@ public class BotiCordClient(
}
}

public suspend fun <T> boticord(
block: suspend BotiCordClient.() -> T
): T = BotiCordClient(null).block()

public suspend fun <T> boticord(
token: String,
block: suspend BotiCordClient.() -> T
): T = BotiCordClient(token).block()

@OptIn(DelicateCoroutinesApi::class)
public fun <T> boticord(
scope: CoroutineScope = GlobalScope,
Expand All @@ -133,4 +142,7 @@ public fun <T> boticordBlocking(
): T = runBlocking { BotiCordClient(token).block() }

public fun boticord(token: String): BotiCordClient =
BotiCordClient(token)
BotiCordClient(token)

public fun boticord(): BotiCordClient =
BotiCordClient(null)

0 comments on commit 80a1af7

Please sign in to comment.