All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.devslash.pipes.Pipe.kt Maven / Gradle / Ivy

There is a newer version: 0.26.2
Show newest version
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