1
1
package concurrent
2
2
3
3
import scala .collection .mutable , mutable .ListBuffer
4
- import scala . util .boundary
4
+ import fiberRuntime .boundary
5
5
import scala .compiletime .uninitialized
6
6
import scala .util .{Try , Success , Failure }
7
7
import scala .annotation .unchecked .uncheckedVariance
@@ -16,11 +16,6 @@ trait Future[+T] extends Async.OriginalSource[Try[T]], Cancellable:
16
16
*/
17
17
def value (using async : Async ): T
18
18
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
-
24
19
/** Eventually stop computation of this future and fail with
25
20
* a `Cancellation` exception. Also cancel all children.
26
21
*/
@@ -81,10 +76,6 @@ object Future:
81
76
def value (using async : Async ): T =
82
77
async.await(this ).get
83
78
84
- def force (): T = synchronized :
85
- while ! hasCompleted do wait()
86
- result.get
87
-
88
79
/** Complete future with result. If future was cancelled in the meantime,
89
80
* return a CancellationException failure instead.
90
81
* Note: @uncheckedVariance is safe here since `complete` is called from
@@ -99,8 +90,6 @@ object Future:
99
90
this .result = result
100
91
hasCompleted = true
101
92
for listener <- extract(waiting) do listener(result)
102
- synchronized :
103
- notifyAll()
104
93
105
94
end CoreFuture
106
95
@@ -151,7 +140,8 @@ object Future:
151
140
* If either task succeeds, succeed with the success that was returned first
152
141
* and cancel the other. Otherwise, fail with the failure that was returned last.
153
142
*/
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)
155
145
Async .await(Async .either(f1, f2)) match
156
146
case Left (Success (x1)) => f2.cancel(); x1
157
147
case Right (Success (x2)) => f1.cancel(); x2
@@ -210,5 +200,5 @@ def add(x: Future[Int], xs: List[Future[Int]])(using Scheduler): Future[Int] =
210
200
end add
211
201
212
202
def Main (x : Future [Int ], xs : List [Future [Int ]])(using Scheduler ): Int =
213
- add(x, xs).force( )
203
+ Async .blocking( add(x, xs).value )
214
204
0 commit comments