diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 14:31:59 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 14:31:59 -0700 |
commit | 9f62900145029786457f27c1fe3083cde5d83fe2 (patch) | |
tree | 23a98110e11194b232f619f66472ed0acabbda17 | |
parent | f0ca5aec4c575fe297adcd3e2b16018fff4a0639 (diff) | |
parent | 96a70e31f34be3eb1f3396ebbc74845659ea7e15 (diff) | |
download | scala-9f62900145029786457f27c1fe3083cde5d83fe2.tar.gz scala-9f62900145029786457f27c1fe3083cde5d83fe2.tar.bz2 scala-9f62900145029786457f27c1fe3083cde5d83fe2.zip |
Merge pull request #2983 from retronym/merge/2.10.3-to-2.10.x
Merge/2.10.3 to 2.10.x
-rw-r--r-- | build.xml | 54 | ||||
-rw-r--r-- | src/library/scala/concurrent/Future.scala | 11 | ||||
-rw-r--r-- | test/files/run/future-flatmap-exec-count.check | 6 | ||||
-rw-r--r-- | test/files/run/future-flatmap-exec-count.scala | 61 |
4 files changed, 119 insertions, 13 deletions
@@ -1881,18 +1881,60 @@ TODO: </copy> </target> + <!-- + A jar-like task that creates an OSGi source bundle. It adds the required MANIFEST.MF headers that allow + Eclipse to match sources with the corresponding binaries. + --> + <macrodef name="osgi.source.bundle"> + <attribute name="destfile" description="The jar file name"/> + <attribute name="symbolicName" description="The original bundle symbolic name (without .source at the end)"/> + <attribute name="bundleName" description="A value for Bundle-Name, usually a textual description"/> + <element name="file-sets" description="A sequence of fileset elements to be included in the jar" optional="true" implicit="true"/> + + <sequential> + <jar whenmanifestonly="fail" destfile="@{destFile}"> + <file-sets/> + <manifest> + <attribute name="Manifest-Version" value="1.0"/> + <attribute name="Bundle-Name" value="@{bundleName}"/> + <attribute name="Bundle-SymbolicName" value="@{symbolicName}.source"/> + <attribute name="Bundle-Version" value="${osgi.version.number}"/> + <attribute name="Eclipse-SourceBundle" value="@{symbolicName};version="${osgi.version.number}";roots:="."" /> + </manifest> + </jar> + </sequential> + </macrodef> + <target name="dist.src" depends="dist.base"> <mkdir dir="${dist.dir}/src"/> - <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-library-src.jar"> + <osgi.source.bundle destfile="${dist.dir}/src/scala-library-src.jar" + symbolicName="org.scala-lang.scala-library" + bundleName="Scala Library Sources"> <fileset dir="${src.dir}/library"/> <fileset dir="${src.dir}/continuations/library"/> - </jar> - <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-reflect-src.jar" basedir="${src.dir}/reflect"/> - <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-swing-src.jar" basedir="${src.dir}/swing"/> - <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-compiler-src.jar" basedir="${src.dir}/compiler"/> + </osgi.source.bundle> + <osgi.source.bundle destfile="${dist.dir}/src/scala-reflect-src.jar" + symbolicName="org.scala-lang.scala-reflect" + bundleName="Scala Reflect Sources"> + <fileset dir="${src.dir}/reflect"/> + </osgi.source.bundle> + <osgi.source.bundle destfile="${dist.dir}/src/scala-swing-src.jar" + symbolicName="org.scala-lang.scala-swing" + bundleName="Scala Swing Sources"> + <fileset dir="${src.dir}/swing"/> + </osgi.source.bundle> + <osgi.source.bundle destfile="${dist.dir}/src/scala-compiler-src.jar" + symbolicName="org.scala-lang.scala-compiler" + bundleName="Scala Compiler Sources"> + <fileset dir="${src.dir}/compiler"/> + </osgi.source.bundle> <jar whenmanifestonly="fail" destfile="${dist.dir}/src/fjbg-src.jar" basedir="${src.dir}/fjbg"/> <jar whenmanifestonly="fail" destfile="${dist.dir}/src/msil-src.jar" basedir="${src.dir}/msil"/> - <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-actors-src.jar" basedir="${src.dir}/actors"/> + <osgi.source.bundle destfile="${dist.dir}/src/scala-actors-src.jar" + symbolicName="org.scala-lang.scala-actors" + bundleName="Scala Actors Sources"> + <fileset dir="${src.dir}/actors"/> + </osgi.source.bundle> <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scalap-src.jar" basedir="${src.dir}/scalap"/> <jar whenmanifestonly="fail" destfile="${dist.dir}/src/scala-partest-src.jar" basedir="${src.dir}/partest"/> </target> diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index caf91fbb0f..39946e4472 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -96,11 +96,8 @@ trait Future[+T] extends Awaitable[T] { // of the Future trait. Note that this will // (modulo bugs) _never_ execute a callback // other than those below in this same file. - // As a nice side benefit, having this implicit - // here forces an ambiguity in those methods - // that also have an executor parameter, which - // keeps us from accidentally forgetting to use - // the executor parameter. + // + // See the documentation on `InternalCallbackExecutor` for more details. private def internalExecutor = Future.InternalCallbackExecutor /* Callbacks */ @@ -254,7 +251,7 @@ trait Future[+T] extends Awaitable[T] { case Success(v) => try f(v) match { // If possible, link DefaultPromises to avoid space leaks case dp: DefaultPromise[_] => dp.asInstanceOf[DefaultPromise[S]].linkRootOf(p) - case fut => fut onComplete p.complete + case fut => fut.onComplete(p.complete)(internalExecutor) } catch { case NonFatal(t) => p failure t } } p.future @@ -344,7 +341,7 @@ trait Future[+T] extends Awaitable[T] { def recoverWith[U >: T](pf: PartialFunction[Throwable, Future[U]])(implicit executor: ExecutionContext): Future[U] = { val p = Promise[U]() onComplete { - case Failure(t) => try pf.applyOrElse(t, (_: Throwable) => this) onComplete p.complete catch { case NonFatal(t) => p failure t } + case Failure(t) => try pf.applyOrElse(t, (_: Throwable) => this).onComplete(p.complete)(internalExecutor) catch { case NonFatal(t) => p failure t } case other => p complete other } p.future diff --git a/test/files/run/future-flatmap-exec-count.check b/test/files/run/future-flatmap-exec-count.check new file mode 100644 index 0000000000..dd9dce64ed --- /dev/null +++ b/test/files/run/future-flatmap-exec-count.check @@ -0,0 +1,6 @@ +mapping +execute() +flatmapping +execute() +recovering +execute() diff --git a/test/files/run/future-flatmap-exec-count.scala b/test/files/run/future-flatmap-exec-count.scala new file mode 100644 index 0000000000..86c37be938 --- /dev/null +++ b/test/files/run/future-flatmap-exec-count.scala @@ -0,0 +1,61 @@ +import scala.concurrent._ +import java.util.concurrent.atomic.AtomicInteger + +object Test { + def main(args: Array[String]) { + test() + } + + def test() = { + def await(f: Future[Any]) = + Await.result(f, duration.Duration.Inf) + + val ec = new TestExecutionContext(ExecutionContext.Implicits.global) + + { + val p = Promise[Int]() + val fp = p.future + println("mapping") + val mapped = fp.map(x => x)(ec) + p.success(0) + await(mapped) + } + + { + println("flatmapping") + val p = Promise[Int]() + val fp = p.future + val flatMapped = fp.flatMap({ (x: Int) => + Future.successful(2 * x) + })(ec) + p.success(0) + await(flatMapped) + } + + { + println("recovering") + val recovered = Future.failed(new Throwable()).recoverWith { + case _ => Future.successful(2) + }(ec) + await(recovered) + } + } + + class TestExecutionContext(delegate: ExecutionContext) extends ExecutionContext { + def execute(runnable: Runnable): Unit = ??? + + def reportFailure(t: Throwable): Unit = ??? + + override def prepare(): ExecutionContext = { + val preparedDelegate = delegate.prepare() + return new ExecutionContext { + def execute(runnable: Runnable): Unit = { + println("execute()") + preparedDelegate.execute(runnable) + } + + def reportFailure(t: Throwable): Unit = ??? + } + } + } +} |