@@ -24,7 +24,7 @@ class FutureSpec {
2424 /* some utils */
2525
2626 def testAsync (s : String )(implicit ec : ExecutionContext ): Future [String ] = s match {
27- case " Hello" => future { " World" }
27+ case " Hello" => Future { " World" }
2828 case " Failure" => Future .failed(new RuntimeException (" Expected exception; to test fault-tolerance" ))
2929 case " NoReply" => Promise [String ]().future
3030 }
@@ -42,7 +42,7 @@ class FutureSpec {
4242
4343 class ThrowableTest (m : String ) extends Throwable (m)
4444
45- val f1 = future [Any ] {
45+ val f1 = Future [Any ] {
4646 throw new ThrowableTest (" test" )
4747 }
4848
@@ -51,7 +51,7 @@ class FutureSpec {
5151 }
5252
5353 val latch = new TestLatch
54- val f2 = future {
54+ val f2 = Future {
5555 Await .ready(latch, 5 seconds)
5656 " success"
5757 }
@@ -72,7 +72,7 @@ class FutureSpec {
7272
7373 Await .result(f3, defaultTimeout) mustBe (" SUCCESS" )
7474
75- val waiting = future {
75+ val waiting = Future {
7676 Thread .sleep(1000 )
7777 }
7878 Await .ready(waiting, 2000 millis)
@@ -86,8 +86,8 @@ class FutureSpec {
8686 @ Test def `A future with global ExecutionContext should compose with for-comprehensions` () {
8787 import scala .reflect .ClassTag
8888
89- def asyncInt (x : Int ) = future { (x * 2 ).toString }
90- val future0 = future [Any ] {
89+ def asyncInt (x : Int ) = Future { (x * 2 ).toString }
90+ val future0 = Future [Any ] {
9191 " five!" .length
9292 }
9393
@@ -100,8 +100,8 @@ class FutureSpec {
100100
101101 val future2 = async {
102102 val a = await(future0.mapTo[Int ])
103- val b = await((future { (a * 2 ).toString }).mapTo[Int ])
104- val c = await(future { (7 * 2 ).toString })
103+ val b = await((Future { (a * 2 ).toString }).mapTo[Int ])
104+ val c = await(Future { (7 * 2 ).toString })
105105 b + " -" + c
106106 }
107107
@@ -115,8 +115,8 @@ class FutureSpec {
115115 case class Req [T ](req : T )
116116 case class Res [T ](res : T )
117117 def asyncReq [T ](req : Req [T ]) = req match {
118- case Req (s : String ) => future { Res (s.length) }
119- case Req (i : Int ) => future { Res ((i * 2 ).toString) }
118+ case Req (s : String ) => Future { Res (s.length) }
119+ case Req (i : Int ) => Future { Res ((i * 2 ).toString) }
120120 }
121121
122122 val future1 = for {
@@ -217,7 +217,7 @@ class FutureSpec {
217217 @ Test def `andThen like a boss` () {
218218 val q = new java.util.concurrent.LinkedBlockingQueue [Int ]
219219 for (i <- 1 to 1000 ) {
220- val chained = future {
220+ val chained = Future {
221221 q.add(1 ); 3
222222 } andThen {
223223 case _ => q.add(2 )
@@ -244,7 +244,7 @@ class FutureSpec {
244244 }
245245
246246 @ Test def `find` () {
247- val futures = for (i <- 1 to 10 ) yield future {
247+ val futures = for (i <- 1 to 10 ) yield Future {
248248 i
249249 }
250250
@@ -279,27 +279,29 @@ class FutureSpec {
279279
280280 @ Test def `fold` () {
281281 val timeout = 10000 millis
282- def async (add : Int , wait : Int ) = future {
282+ def async (add : Int , wait : Int ) = Future {
283283 Thread .sleep(wait)
284284 add
285285 }
286286
287287 val futures = (0 to 9 ) map {
288288 idx => async(idx, idx * 20 )
289289 }
290+ // TODO: change to `foldLeft` after support for 2.11 is dropped
290291 val folded = Future .fold(futures)(0 )(_ + _)
291292 Await .result(folded, timeout) mustBe (45 )
292293
293294 val futuresit = (0 to 9 ) map {
294295 idx => async(idx, idx * 20 )
295296 }
297+ // TODO: change to `foldLeft` after support for 2.11 is dropped
296298 val foldedit = Future .fold(futures)(0 )(_ + _)
297299 Await .result(foldedit, timeout) mustBe (45 )
298300 }
299301
300302 @ Test def `fold by composing` () {
301303 val timeout = 10000 millis
302- def async (add : Int , wait : Int ) = future {
304+ def async (add : Int , wait : Int ) = Future {
303305 Thread .sleep(wait)
304306 add
305307 }
@@ -314,14 +316,15 @@ class FutureSpec {
314316
315317 @ Test def `fold with an exception` () {
316318 val timeout = 10000 millis
317- def async (add : Int , wait : Int ) = future {
319+ def async (add : Int , wait : Int ) = Future {
318320 Thread .sleep(wait)
319321 if (add == 6 ) throw new IllegalArgumentException (" shouldFoldResultsWithException: expected" )
320322 add
321323 }
322324 def futures = (0 to 9 ) map {
323325 idx => async(idx, idx * 10 )
324326 }
327+ // TODO: change to `foldLeft` after support for 2.11 is dropped
325328 val folded = Future .fold(futures)(0 )(_ + _)
326329 intercept[IllegalArgumentException ] {
327330 Await .result(folded, timeout)
@@ -332,6 +335,7 @@ class FutureSpec {
332335 import scala .collection .mutable .ArrayBuffer
333336 def test (testNumber : Int ) {
334337 val fs = (0 to 1000 ) map (i => Future (i))
338+ // TODO: change to `foldLeft` after support for 2.11 is dropped
335339 val f = Future .fold(fs)(ArrayBuffer .empty[AnyRef ]) {
336340 case (l, i) if i % 2 == 0 => l += i.asInstanceOf [AnyRef ]
337341 case (l, _) => l
@@ -345,28 +349,31 @@ class FutureSpec {
345349 }
346350
347351 @ Test def `return zero value if folding empty list` () {
352+ // TODO: change to `foldLeft` after support for 2.11 is dropped
348353 val zero = Future .fold(List [Future [Int ]]())(0 )(_ + _)
349354 Await .result(zero, defaultTimeout) mustBe (0 )
350355 }
351356
352357 @ Test def `shouldReduceResults` () {
353- def async (idx : Int ) = future {
358+ def async (idx : Int ) = Future {
354359 Thread .sleep(idx * 20 )
355360 idx
356361 }
357362 val timeout = 10000 millis
358363
359364 val futures = (0 to 9 ) map { async }
365+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
360366 val reduced = Future .reduce(futures)(_ + _)
361367 Await .result(reduced, timeout) mustBe (45 )
362368
363369 val futuresit = (0 to 9 ) map { async }
370+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
364371 val reducedit = Future .reduce(futuresit)(_ + _)
365372 Await .result(reducedit, timeout) mustBe (45 )
366373 }
367374
368375 @ Test def `shouldReduceResultsWithException` () {
369- def async (add : Int , wait : Int ) = future {
376+ def async (add : Int , wait : Int ) = Future {
370377 Thread .sleep(wait)
371378 if (add == 6 ) throw new IllegalArgumentException (" shouldFoldResultsWithException: expected" )
372379 else add
@@ -375,6 +382,7 @@ class FutureSpec {
375382 def futures = (1 to 10 ) map {
376383 idx => async(idx, idx * 10 )
377384 }
385+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
378386 val failed = Future .reduce(futures)(_ + _)
379387 intercept[IllegalArgumentException ] {
380388 Await .result(failed, timeout)
@@ -383,6 +391,7 @@ class FutureSpec {
383391
384392 @ Test def `shouldReduceThrowNSEEOnEmptyInput` () {
385393 intercept[java.util.NoSuchElementException ] {
394+ // TODO: change to `reduceLeft` after support for 2.11 is dropped
386395 val emptyreduced = Future .reduce(List [Future [Int ]]())(_ + _)
387396 Await .result(emptyreduced, defaultTimeout)
388397 }
@@ -397,7 +406,7 @@ class FutureSpec {
397406 }
398407 }
399408
400- val oddFutures = List .fill(100 )(future { counter.incAndGet() }).iterator
409+ val oddFutures = List .fill(100 )(Future { counter.incAndGet() }).iterator
401410 val traversed = Future .sequence(oddFutures)
402411 Await .result(traversed, defaultTimeout).sum mustBe (10000 )
403412
@@ -413,11 +422,11 @@ class FutureSpec {
413422 @ Test def `shouldBlockUntilResult` () {
414423 val latch = new TestLatch
415424
416- val f = future {
425+ val f = Future {
417426 Await .ready(latch, 5 seconds)
418427 5
419428 }
420- val f2 = future {
429+ val f2 = Future {
421430 val res = Await .result(f, Inf )
422431 res + 9
423432 }
@@ -430,7 +439,7 @@ class FutureSpec {
430439
431440 Await .result(f2, defaultTimeout) mustBe (14 )
432441
433- val f3 = future {
442+ val f3 = Future {
434443 Thread .sleep(100 )
435444 5
436445 }
@@ -443,7 +452,7 @@ class FutureSpec {
443452 @ Test def `run callbacks async` () {
444453 val latch = Vector .fill(10 )(new TestLatch )
445454
446- val f1 = future {
455+ val f1 = Future {
447456 latch(0 ).open()
448457 Await .ready(latch(1 ), TestLatch .DefaultTimeout )
449458 " Hello"
@@ -535,7 +544,7 @@ class FutureSpec {
535544
536545 @ Test def `should not throw when Await.ready` () {
537546 val expected = try Success (5 / 0 ) catch { case a : ArithmeticException => Failure (a) }
538- val f = async { await(future (5 )) / 0 }
547+ val f = async { await(Future (5 )) / 0 }
539548 Await .ready(f, defaultTimeout).value.get.toString mustBe expected.toString
540549 }
541550}
0 commit comments