我正在尝试使用Scala版本2.11.7实现《Scala by Example》书中第17.9节"Workers"。导入语句如下:
发生了错误 "ops not is member of scala.concurrent"。我进行了谷歌搜索,得知 concurrent.ops 已被弃用,应该改为使用 future,请将导入语句改为:
整个班级的来源:
但是在这一行中出现了错误:
“在2.11.7版本中,'spawn'、'replicate'和'processor function'是什么?”
import scala.concurrent._, scala.concurrent.ops._
发生了错误 "ops not is member of scala.concurrent"。我进行了谷歌搜索,得知 concurrent.ops 已被弃用,应该改为使用 future,请将导入语句改为:
import scala.concurrent._, scala.concurrent.Future._
整个班级的来源:
import scala.concurrent._
import scala.concurrent.Future._
class ComputeServer(n: Int) {
private abstract class Job {
type T
def task: T
def res(x: T)
}
private val openJobs = new Channel[Job]()
private def processor(i: Int) {
while(true) {
val job = openJobs.read
job.res(job.task)
}
}
def future[A](p: => A): () => A = {
val reply = new SyncVar[A]()
openJobs.write{
new Job{
type T = A
def task = p
def res(x: A) = reply.put(x)
}
}
() => reply.get
}
spawn(replicate(0, n){processor})
}
但是在这一行中出现了错误:
spawn(replicate(0, n){processor})
。not found: value spawn
not found: value replicate
missing arguments for method processor in class ComputeServer; follow this method with `_' if you want to treat it as a partially applied function
“在2.11.7版本中,'spawn'、'replicate'和'processor function'是什么?”