0

I m trying out the example given at http://dispatch-classic.databinder.net/Choose+an+Executor.html for dispatch-nio: Example given:

import dispatch._
val h = new nio.Http
val f = h(url("http://www.scala-lang.org/") as_str)

My code:

  import dispatch._
  val h = new nio.Http
  var host = "http://www.scala-lang.org";
    val f: Future[String] = h(url("http://www.scala-lang.org/") as_str)
    f.apply();

But it doesn't recognize nio and as_str keywords. Could anyone please suggest what would be the problem?

Urist McDev
  • 498
  • 3
  • 14
DSKVP
  • 663
  • 2
  • 11
  • 19
  • What is in your build.sbt? – Callum May 19 '15 at 21:27
  • name := "blank" version := "1.0-SNAPSHOT" scalaVersion := "2.10.2" resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" libraryDependencies ++= Seq ( "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test" ) libraryDependencies ++= Seq( "net.databinder" %% "dispatch" % "0.8.10" ) libraryDependencies ++= Seq( "net.databinder.dispatch" %% "dispatch-core" % "0.11.2" ) libraryDependencies ++= Seq( "net.databinder" %% "dispatch-http" % "0.8.10" ) libraryDependencies ++= Seq( "net.databinder" %% "dispatch-nio" % "0.8.10" ) – DSKVP May 19 '15 at 21:46
  • Try changing the dispatch-nio dependency to the one from my answer and import dispatch.classic._ in the code – Callum May 19 '15 at 21:50

1 Answers1

1

I'm not sure of your version but I've got it to work with 0.8.1, the namespace looks like it's changed from the documentation.

In build.sbt:

libraryDependencies += "net.databinder" %% "dispatch-nio_2.10.2" % "0.8.1"

In code:

import dispatch.classic._

val h = new nio.Http
var host = "http://www.scala-lang.org";
val f = h(url("http://www.scala-lang.org/") as_str)
f.apply()

You may need to substitute the 2.10.2 in the library dependency with your scala version number.

Callum
  • 869
  • 5
  • 23
  • Thanks for the reply @Spork. It is working. Where can I find the updated documentation of dispatcher? – DSKVP May 19 '15 at 21:55
  • No problem, as far as I'm aware the only documentation is on the website. I managed to find the change using import completion in my IntelliJ IDE. You can always check the project on GitHub if the documentation doesn't seem to be working. https://github.com/dispatch/dispatch – Callum May 19 '15 at 21:58
  • I would like to know that if I use dispatch.Http then I cannot use nio.Http ?? Thank you. – DSKVP May 19 '15 at 22:06