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

gopher.GopherAPI.scala Maven / Gradle / Ivy

Go to download

scala-gopher: asynchronous implementation of CSP ( go-like channels/selectors ) in scala

The newest version!
package gopher

import cps._

trait GopherConfig
case object DefaultGopherConfig extends GopherConfig


  
trait GopherAPI: 

  def apply[F[_]:CpsSchedulingMonad](cfg:GopherConfig = DefaultGopherConfig): Gopher[F]
          
/**
 * Shared gopehr api, which is initialized by platofrm part,
 * Primary used for cross-platforming test, you shoul initialize one of platform API
 *  behind and then run tests.
 **/
object SharedGopherAPI {

  private[this] var _api: Option[GopherAPI] = None

  def apply[F[_]:CpsSchedulingMonad](cfg:GopherConfig = DefaultGopherConfig): Gopher[F] =
    api.apply[F](cfg)



  def api: GopherAPI = 
    if (_api.isEmpty) then
      initPlatformSpecific()  
    _api.get


  private[gopher] def setApi(api: GopherAPI): Unit =
    this._api = Some(api)


  private[gopher] def initPlatformSpecific(): Unit =
    Platform.initShared()   
 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy