org.scalajs.nodejs.drama.Actor.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalajs-npm-drama_sjs0.6_2.11 Show documentation
Show all versions of scalajs-npm-drama_sjs0.6_2.11 Show documentation
npm/drama binding for Scala.js
The newest version!
package org.scalajs.nodejs.drama
import org.scalajs.nodejs.util.ScalaJsHelper._
import org.scalajs.nodejs.util.ScalaJsHelper
import scala.scalajs.js
/**
* Actor
* @author [email protected]
*/
@js.native
trait Actor extends js.Object {
/**
* Requests state of the given method the specified actor
* @param actor the specified actor
* @param method the given method
* @param callback the response callback
*/
def ask(actor: Actor, method: String, callback: js.Function): Unit = js.native
/**
* Initializes an actor with the given initial value
* @param initialValue the given initial value
*/
def init(initialValue: js.Any): Unit = js.native
/**
* Returns a proxy implementing the corresponding methods
* @param methods the corresponding methods
* @return the proxy
*/
def pick(methods: String*): js.Dynamic = js.native
/**
* Sends the given message to the specified method
* @param method the given message
* @param message the specified method
*/
def tell(method: String, message: js.Any): Unit = js.native
}
/**
* Actor Companion
* @author [email protected]
*/
object Actor {
/**
* Actor Extensions
* @param actor the given [[Actor actor]]
*/
implicit class ActorExtensions(val actor: Actor) extends AnyVal {
/**
* Sends the given message to the specified method
* @param request the method/message tuple
*/
@inline
def !(request: (String, js.Any)) = actor.tell(request._1, request._2)
/**
* Requests state of the given method the specified actor
* @param method the given method
* @return the promise of the state
*/
@inline
def ?(method: String) = askFuture(method)
/**
* Requests state of the given method the specified actor
* @param method the given method
* @return the promise of the state
*/
@inline
def askFuture(method: String) = futureCallbackA1[js.Any](actor.ask(actor, method, _))
}
}