net.devslash.pipes.Pipe.kt Maven / Gradle / Ivy
package net.devslash.pipes
import net.devslash.*
import java.util.concurrent.ConcurrentLinkedDeque
class Pipe private constructor(
val acceptor: (HttpResponse, T) -> List>
):
ResolvedFullDataAfterHook, RequestDataSupplier {
companion object {
operator fun invoke(acceptor: (HttpResponse, List) -> List>): Pipe, Y> {
return Pipe(acceptor)
}
@JvmName("invokeTyped")
operator fun invoke(acceptor: (HttpResponse, T) -> List>): Pipe {
return Pipe(acceptor)
}
}
private val storage = ConcurrentLinkedDeque>()
override suspend fun getDataForRequest(): RequestData? {
return storage.poll() ?: return null
}
override fun accept(req: HttpRequest, resp: HttpResponse, data: T) {
val newResults = acceptor(resp, data)
storage.addAll(newResults)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy