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

net.devslash.Providers.kt Maven / Gradle / Ivy

There is a newer version: 0.26.2
Show newest version
package net.devslash

import java.util.concurrent.atomic.AtomicBoolean


fun  handleNoSupplier(data: RequestDataSupplier?): RequestDataSupplier {
  if (data != null) {
    data.init()
    return data
  }

  // The default re
  return SingleUseDataSupplier()
}

class SingleUseDataSupplier(supply: List = listOf()) : RequestDataSupplier {

  @Suppress("UNCHECKED_CAST")
  private val unsafeSupply: T = supply as T
  private val first = AtomicBoolean(true)

  override suspend fun getDataForRequest(): RequestData? {
    if (first.compareAndSet(true, false)) {
      return object : RequestData() {
        override fun  visit(visitor: RequestVisitor): T {
          return visitor(unsafeSupply, List::class.java)
        }

        override fun get(): T = unsafeSupply
      }
    }
    return null
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy