def async[A](body: => A @suspendable) = {
val p = promise[A]
reset { p success body }
p
}
work for the extended case you mention?
val a: Future[Int] = async[Int] {
val com = await { dlWebSite("http://www.google.com") }
com.length
}
a onSuccess { case r => .... }
- Tiark
http://akka.io/docs/akka/2.0-RC1/scala/dataflow.html
Cheers,
√
--
Viktor Klang
Akka Tech Lead
Typesafe - The software stack for applications that scale
Twitter: @viktorklang
def flow[A](body: => A @cps[Future[Any]]): Future[A]
def async[A](body: => A @suspendable): Future[A]
this one avoids the Future[Any] part.
- Tiark
What are the pros/cons?
That's a good one! Let me see what we can do about that.
Cheers,
√
>
> Daniel
This is maybe also worth a discussion:
def namedCtx(n: String) = ExecutionContexts.fromExecutor(
Executors.newSingleThreadExecutor( new ThreadFactory {
def newThread(r: Runnable) = new Thread(r,n)
}))
val A = namedCtx("A")
val B = namedCtx("B")
// create a promise with ctx A
val p = Promise[String]()(A)
// I would expect that any callback from p
// is executed in the context of p
p onSuccess{
case r => println(Thread.currentThread().getName() + " " + r)
}
p.completeWith(Future{"Hi"}(B))
The above prints "B Hi"
What do you think?
2012/2/16 Daniel Kröni <daniel...@gmail.com>:
final def completeWith(other: Future[T]): this.type = {
other onComplete { tryComplete(_) }
this
}
Cheers,
√
2012/2/16 Tiark Rompf <tiark...@epfl.ch>:
> Yes, the differences are minor:What are the pros/cons?
>
> def flow[A](body: => A @cps[Future[Any]]): Future[A]
>
> def async[A](body: => A @suspendable): Future[A]
>
> this one avoids the Future[Any] part.
bad option: -P:continuations:enable
I tried enabling "Use Project Settings" and setting
"continuations:enable" in the P field, but that just produces "bad
option: -P:continuations:enable" as well.
This has been my ongoing problem with continuations in Scala - it is
simply too difficult to configure it to work in Eclipse - consequently I
cannot even experiment with the feature.
Should I create a JIRA issue on this?
Cheers, Eric
It sounds like you are using Scala 2.8.x... are you?
--
Daniel C. Sobral
I travel to the future all the time.
Cheers, Eric
Kinda sucks that the path in the Xplugin cannot have any spaces in the
name. I had to move the plug-in somewhere else. My Scala is installed in
C:\Program Files (Open)\Scala\scala-2.9.0.1
I guess continuations are still consider experimental which is why there
is so much fuss around setting them up in Eclipse.
Cheers, Eric
Enabling the continuations plugin in the Scala IDE for Eclipse is actually very simple, and to help
with that I just wrote a short tutorial:
http://scala-ide.org/docs/tutorials/continuations-plugin/index.html
There is no need to explicitly pass -Xplugin, that because the continuations.jar is shipped together
with the Scala distribution and by default -Xpluginsdir points to the directory containing the
continuations.jar.
If you have any comment, please feel free to drop me an email.
Cheers,
Mirco
That's strange, but there may be a bug we don't know of. Would you mind discussing this
on the scala-ide-user ML?
Below is the link to the discussion
http://groups.google.com/group/scala-ide-user/browse_thread/thread/cd6c9a23fe099ab8
-- Mirco
However, I was not able to get this to work until I set the path to the
continuations.jar in the -Xplugin field.
As I noted, there is a problem with spaces in path names (which should
not be a problem in the year 2012 with any software), and perhaps that
is why this did not work with -Xpluginsdir either. Should I create a
JIRA issue regarding this?
Cheers, Eric
http://scala-ide.org/download/nightly.html
You can read the tutorial to learn how to successfully enable continuations in the Scala IDE
http://scala-ide.org/docs/tutorials/continuations-plugin/index.html
Thanks guys for the feedback and, please, keep reporting issues you see in the Scala IDE for Eclipse,
that's really the only way we can make your daily Scala hacking better and better :)
Cheers,
Mirco