-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
31 changed files
with
521 additions
and
392 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
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
9 changes: 7 additions & 2 deletions
9
...ws-events-client/src/commonMain/kotlin/dev/d1s/ktor/events/client/ClientWebSocketEvent.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,10 +1,15 @@ | ||
package dev.d1s.ktor.events.client | ||
|
||
import dev.d1s.ktor.events.commons.AbstractEvent | ||
import dev.d1s.ktor.events.commons.EventReference | ||
import dev.d1s.ktor.events.commons.Identifier | ||
import dev.d1s.ktor.events.commons.UnixTime | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
public data class ClientWebSocketEvent<T>( | ||
val reference: EventReference, | ||
override val id: Identifier, | ||
override val reference: EventReference, | ||
override val initiated: UnixTime, | ||
val data: T | ||
) | ||
) : AbstractEvent |
35 changes: 35 additions & 0 deletions
35
ktor-ws-events-client/src/commonMain/kotlin/dev/d1s/ktor/events/client/Retries.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,35 @@ | ||
package dev.d1s.ktor.events.client | ||
|
||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.delay | ||
import org.lighthousegames.logging.logging | ||
|
||
private const val DEFAULT_DELAY = 5_000L | ||
|
||
private val logger = logging() | ||
|
||
public suspend fun <R> withRetries( | ||
continuous: Boolean = false, | ||
onError: suspend (Throwable) -> Unit = {}, | ||
block: suspend () -> R | ||
) { | ||
coroutineScope { | ||
while (true) { | ||
try { | ||
block() | ||
|
||
if (!continuous) { | ||
break | ||
} | ||
} catch (e: Throwable) { | ||
logger.d { | ||
"Error while executing; ${e::class.simpleName}: ${e.message}" | ||
} | ||
|
||
onError(e) | ||
|
||
delay(DEFAULT_DELAY) | ||
} | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
ktor-ws-events-commons/src/commonMain/kotlin/dev/d1s/ktor/events/commons/AbstractEvent.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,10 @@ | ||
package dev.d1s.ktor.events.commons | ||
|
||
public interface AbstractEvent { | ||
|
||
public val id: Identifier | ||
|
||
public val reference: EventReference | ||
|
||
public val initiated: UnixTime | ||
} |
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: 8 additions & 0 deletions
8
ktor-ws-events-commons/src/commonMain/kotlin/dev/d1s/ktor/events/commons/Identifier.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,8 @@ | ||
package dev.d1s.ktor.events.commons | ||
|
||
public typealias Identifier = String | ||
|
||
private val chars = ('0'..'9') + ('a'..'z') | ||
|
||
public val randomId: Identifier | ||
get() = chars.shuffled().take(16).joinToString("") |
3 changes: 3 additions & 0 deletions
3
ktor-ws-events-commons/src/commonMain/kotlin/dev/d1s/ktor/events/commons/Time.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,3 @@ | ||
package dev.d1s.ktor.events.commons | ||
|
||
public typealias UnixTime = Long |
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
Oops, something went wrong.