I'm trying to build a coroutine framework to enable batch data fetching by stepping through each data-dependent function in parallel. Here is what I have so far: http://pastie.org/7147798
This doesn't work
def get(id: Long) = reset { // Is it not already cached? if (!cached.isDefinedAt(id)) { // Store the ID we want to fetch. queued += id // Come back later... shift { fetch[Object]() } : Seq[Any] @cps[ExecState[Object]] } // We should have the ID fetched now. Result(cached(id)) }
I get the following error
ashoat@ashoatmbp [~/project]# scala -P:continuations:enable Loader.scala /Users/ashoat/project/Loader.scala:134: error: type mismatch; found : Unit required: Any @util.continuations.package.cps[Main.$anon.Loader.ExecState[Main.$anon.Loader.Object]] if (!cached.isDefinedAt(id)) { ^ one error found
This works
def get(id: Long) = reset { // Is it not already cached? if (!cached.isDefinedAt(id)) { // Store the ID we want to fetch. queued += id // Come back later... shift { fetch[Object]() } : Seq[Any] @cps[ExecState[Object]] // We should have the ID fetched now. Result(cached(id)) } else { // We should have the ID fetched now. Result(cached(id)) } }
This doesn't work
val getFive = reset { if (true) { Result(5) } else { val seq: Seq[Any] = shift { fetch[Int](Object.get(15181990251L)) } val Seq(obj: Object) = seq Result(obj.fields("test").toInt) } }
I get the following error
ashoat@ashoatmbp [~/project]# scala -P:continuations:enable Loader.scala /Users/ashoat/project/Loader.scala:170: error: cannot cps-transform expression new this.Loader.Result[Int](5): type arguments [this.Loader.Result[Int],this.Loader.Result[Int],Nothing] do not conform to method shiftUnit's type parameter bounds [A,B,C >: B] Result(5)// : Result[Int] @cps[Result[Int]] ^ one error found
This works
val getFive = reset { if (true) { Result(5) : Result[Int] @cps[Result[Int]] } else { val seq: Seq[Any] = shift { fetch[Int](Object.get(15181990251L)) } val Seq(obj: Object) = seq Result(obj.fields("test").toInt) } }
But I get the following warning
ashoat@ashoatmbp [~/project]# scala -P:continuations:enable Loader.scala /Users/ashoat/project/Loader.scala:170: warning: expression (new this.Loader.Result[Int](5): this.Loader.Result[Int]) is cps-transformed unexpectedly Result(5) : Result[Int] @cps[Result[Int]] ^ one warning found 8