val f = m[ (String, Promise[Int]) ] // choose String and Int types arbitrarily
site(go { case f((x, promiseR)) => .... promiseR.succeed(123) ... })
val p = Promise[Int]()
f("abc", p)
val futureR = p.future
// Done. We got a future that resolves when a reply to f is sent.
Chymyst
:
val f = b[String, Int]
site(go { case f(x, reply) => .... reply(123) ... })
val futureR = f.futureReply("abc") // We got a future that resolves when a reply to f is sent.
futureReply()
API is the only available API for blocking molecules, that's just as good.
Chymyst
, I would try to implement only non-blocking molecules, no thread pools, no debugging hooks, and no waiting. This would be a great first step, because a chemical machine with only non-blocking molecules is equally expressive and equally powerful when compared to a chemical machine with blocking molecules.
Thread
object.
Pool
interface, look at Pool.scala
. I need a facility to schedule the execution of a closure, asynchronously.
val closure = x => x + 1 + veryLongCalculation(x)
pool.runClosure(closure, 123)
// runClosure returns quickly, but "closure" is scheduled and will run later, when the run loop comes to that
setTimeout()
API, perhaps.
Future
while keeping in mind that it is going to run in a single-threaded context.