scala - Could not initialize class $line10.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$ -
i starting day weird problem. can't see wrong code. take lines below
import scala.concurrent._ import scala.concurrent.duration._ import scala.util._ import scala.concurrent.executioncontext.implicits.global def f2 = future.failed(new exception("i nothing")) def f1 = future { println("working"); thread.sleep(5000); 1 } val list = list(f2, f1) val consolidated = future.sequence(list) consolidated.oncomplete { case success(_) => println("completed successfully") case failure(e) => println(s"failed ${e.getmessage}") } await.result(consolidated, duration.inf) and :paste in repl. see weird exception
~ > scala welcome scala 2.12.1 (java hotspot(tm) 64-bit server vm, java 1.8.0_121). type in expressions evaluation. or try :help. scala> :paste // entering paste mode (ctrl-d finish) import scala.concurrent._ import scala.concurrent.duration._ import scala.util._ import scala.concurrent.executioncontext.implicits.global def f2 = future.failed(new exception("no work")) def f1 = future { println("working"); thread.sleep(5000); 1 } val list = list(f2, f1) val consolidated = future.sequence(list) consolidated.oncomplete { case success(_) => println("completed successfully") case failure(e) => println(s"failed ${e.getmessage}") } await.result(consolidated, duration.inf) // exiting paste mode, interpreting. java.lang.noclassdeffounderror: not initialize class $line3.$read$$iw$$iw$ @ scala.concurrent.impl.callbackrunnable.run(promise.scala:60) @ scala.concurrent.impl.executioncontextimpl$adaptedforkjointask.exec(executioncontextimpl.scala:140) @ java.util.concurrent.forkjointask.doexec(forkjointask.java:289) @ java.util.concurrent.forkjoinpool$workqueue.runtask(forkjoinpool.java:1056) @ java.util.concurrent.forkjoinpool.runworker(forkjoinpool.java:1692) @ java.util.concurrent.forkjoinworkerthread.run(forkjoinworkerthread.java:157) java.lang.noclassdeffounderror: not initialize class $line3.$read$$iw$$iw$ @ scala.runtime.java8.jfunction0$mci$sp.apply(jfunction0$mci$sp.java:12) @ scala.concurrent.future$.$anonfun$apply$1(future.scala:653) @ scala.util.success.$anonfun$map$1(try.scala:251) @ scala.util.success.map(try.scala:209) @ scala.concurrent.future.$anonfun$map$1(future.scala:287) @ scala.concurrent.impl.promise.liftedtree1$1(promise.scala:29) @ scala.concurrent.impl.promise.$anonfun$transform$1(promise.scala:29) @ scala.concurrent.impl.callbackrunnable.run(promise.scala:60) @ scala.concurrent.impl.executioncontextimpl$adaptedforkjointask.exec(executioncontextimpl.scala:140) @ java.util.concurrent.forkjointask.doexec(forkjointask.java:289) @ java.util.concurrent.forkjoinpool$workqueue.runtask(forkjoinpool.java:1056) @ java.util.concurrent.forkjoinpool.runworker(forkjoinpool.java:1692) @ java.util.concurrent.forkjoinworkerthread.run(forkjoinworkerthread.java:157) java.lang.exception: nothing @ .f2(<console>:16) ... 29 elided scala> i see no reason could not initialize class errors. according me code should print "failed no work"
the problem this
await.result(consolidated, duration.inf) when await future, , future fails, exception contains thrown. due how repl works, having uncaught exception causes of machinery break. seems bug in repl, doesn't seem have been reported yet.
note oncomplete doesn't change result of future. schedules done after future complete. in particular, not consume future. if meant transform future, this:
val transformed: future[string] = consolidated.andthen { case success(v) => "completed successfully" case failure(e) => s"failed ${e.getmessage}" } println(await.result(transformed, duration.inf)) wiki
Comments
Post a Comment