Skip to content

Instantly share code, notes, and snippets.

View amir1376's full-sized avatar
🎯
Focusing

AmirHossein Abdolmotallebi amir1376

🎯
Focusing
View GitHub Profile
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "sing-box config schema",
"type": "object",
"properties": {
"log": {
"$ref": "#/$defs/log.schema.json"
},
"dns": {
"$ref": "#/$defs/dns.schema.json"
@chibatching
chibatching / FlowThrottleDebounce.kt
Last active November 8, 2024 00:44
Throttle and Debounce on Flow Kotlin Coroutines
fun <T> Flow<T>.throttle(waitMillis: Int) = flow {
coroutineScope {
val context = coroutineContext
var nextMillis = 0L
var delayPost: Deferred<Unit>? = null
collect {
val current = SystemClock.uptimeMillis()
if (nextMillis < current) {
nextMillis = current + waitMillis