11package concurrent
22
33import scala .collection .mutable , mutable .ListBuffer
4- import scala . util .boundary
4+ import fiberRuntime .boundary
55import scala .compiletime .uninitialized
66import scala .util .{Try , Success , Failure }
77import scala .annotation .unchecked .uncheckedVariance
@@ -16,11 +16,6 @@ trait Future[+T] extends Async.OriginalSource[Try[T]], Cancellable:
1616 */
1717 def value (using async : Async ): T
1818
19- /** Block thread until future is completed and return result
20- * N.B. This should be parameterized with a timeout.
21- */
22- def force (): T
23-
2419 /** Eventually stop computation of this future and fail with
2520 * a `Cancellation` exception. Also cancel all children.
2621 */
@@ -81,10 +76,6 @@ object Future:
8176 def value (using async : Async ): T =
8277 async.await(this ).get
8378
84- def force (): T = synchronized :
85- while ! hasCompleted do wait()
86- result.get
87-
8879 /** Complete future with result. If future was cancelled in the meantime,
8980 * return a CancellationException failure instead.
9081 * Note: @uncheckedVariance is safe here since `complete` is called from
@@ -99,8 +90,6 @@ object Future:
9990 this .result = result
10091 hasCompleted = true
10192 for listener <- extract(waiting) do listener(result)
102- synchronized :
103- notifyAll()
10493
10594 end CoreFuture
10695
@@ -151,7 +140,8 @@ object Future:
151140 * If either task succeeds, succeed with the success that was returned first
152141 * and cancel the other. Otherwise, fail with the failure that was returned last.
153142 */
154- def alt [T2 >: T1 ](f2 : Future [T2 ])(using Async .Config ): Future [T2 ] = Future :
143+ def alt [T2 >: T1 ](f2 : Future [T2 ], name : String = " alt" )(using Async .Config ): Future [T2 ] = Future :
144+ boundary.setName(name)
155145 Async .await(Async .either(f1, f2)) match
156146 case Left (Success (x1)) => f2.cancel(); x1
157147 case Right (Success (x2)) => f1.cancel(); x2
@@ -210,5 +200,5 @@ def add(x: Future[Int], xs: List[Future[Int]])(using Scheduler): Future[Int] =
210200end add
211201
212202def Main (x : Future [Int ], xs : List [Future [Int ]])(using Scheduler ): Int =
213- add(x, xs).force( )
203+ Async .blocking( add(x, xs).value )
214204
0 commit comments