value unsafePerformSync不是scalaz.concurrent.Task [String]的成员

时间:2016-12-14 09:05:51

标签: scala scalaz

value unsafePerformSync is not a member of scalaz.concurrent.Task[String]
[error]     val x = task.unsafePerformSync
[error]                  ^
[error] one error found

如何解决上述(2.11.8)scalac错误?感谢。

来自以下代码段:

import org.http4s._, org.http4s.dsl._                                  
import org.http4s.client.blaze._
import scalaz._, Scalaz._
import scalaz.concurrent.Task

object Client extends App {
  val client = PooledHttp1Client()
  val httpize = Uri.uri("http://httpize.herokuapp.com")

  def post() = {
    val req = Request(method = Method.POST, uri = httpize / "post").withBody("hello")
    val task = client.expect[String](req)
    val x = task.unsafePerformSync
    println(x)
}

1 个答案:

答案 0 :(得分:2)

自第一个0.13版本以来,http4已经针对Scalaz 7.1.x和7.2.x进行了交叉发布。在Scalaz 7.1.x中,unsafePerformSync只是run(对于理想情况下你永远不应该直接调用的东西,或者在程序中最多只调用一次,这个名字太诱人了。) / p>

所以你有两个选择。如果你想使用Scalaz 7.2(除非你有其他限制,你应该使用它),在你的构建配置中找到这样的一行:

libraryDependencies += "org.http4s" %% "http4s-core" % "0.15.0"

并改为:

libraryDependencies += "org.http4s" %% "http4s-core" % "0.15.0a"

或者您可以坚持使用Scalaz 7.1,只需更改代码即可使用run