Skip to content

Commit 503ec8b

Browse files
committed
Use ExecutionContext instead of Scheduler
1 parent 518f767 commit 503ec8b

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

tests/run/suspend-strawman-2/Async.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package concurrent
22
import java.util.concurrent.atomic.AtomicBoolean
33
import scala.collection.mutable
4+
import scala.concurrent.ExecutionContext
45

56
/** A context that allows to suspend waiting for asynchronous data sources
67
*/
@@ -18,14 +19,15 @@ trait Async:
1819
object Async:
1920

2021
/** The underlying configuration of an async block */
21-
case class Config(scheduler: Scheduler, group: Cancellable.Group)
22+
case class Config(scheduler: ExecutionContext, group: Cancellable.Group)
2223

2324
trait LowPrioConfig:
2425

2526
/** A toplevel async group with given scheduler and a synthetic root that
2627
* ignores cancellation requests
2728
*/
28-
given fromScheduler(using s: Scheduler): Config = Config(s, Cancellable.Unlinked)
29+
given fromExecutionContext(using scheduler: ExecutionContext): Config =
30+
Config(scheduler, Cancellable.Unlinked)
2931

3032
end LowPrioConfig
3133

@@ -57,7 +59,7 @@ object Async:
5759
/** Execute asynchronous computation `body` on currently running thread.
5860
* The thread will suspend when the computation waits.
5961
*/
60-
def blocking[T](body: Async ?=> T)(using Scheduler): T =
62+
def blocking[T](body: Async ?=> T)(using ExecutionContext): T =
6163
body(using Blocking())
6264

6365
/** The currently executing Async context */

tests/run/suspend-strawman-2/Test.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import concurrent.*
44
import fiberRuntime.boundary.setName
5+
import scala.concurrent.ExecutionContext
56

67
@main def Test =
7-
given Scheduler = Scheduler
8+
given ExecutionContext = ExecutionContext.global
89
val x = Future:
910
setName("x")
1011
val a = Future{ setName("xa"); 22 }

tests/run/suspend-strawman-2/channels.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package concurrent
22
import scala.collection.mutable, mutable.ListBuffer
33
import fiberRuntime.boundary, boundary.Label
44
import fiberRuntime.suspend
5-
import java.util.concurrent.CancellationException
5+
import scala.concurrent.ExecutionContext
66
import Async.{Listener, await}
77

88
/** An unbounded asynchronous channel. Senders do not wait for matching
@@ -97,7 +97,7 @@ object SyncChannel:
9797

9898
end SyncChannel
9999

100-
def TestChannel(using Scheduler) =
100+
def TestChannel(using ExecutionContext) =
101101
val c = SyncChannel[Option[Int]]()
102102
Future:
103103
for i <- 0 to 100 do

tests/run/suspend-strawman-2/futures.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import scala.compiletime.uninitialized
77
import scala.util.{Try, Success, Failure}
88
import scala.annotation.unchecked.uncheckedVariance
99
import java.util.concurrent.CancellationException
10+
import scala.concurrent.ExecutionContext
1011

1112
/** A cancellable future that can suspend waiting for other asynchronous sources
1213
*/
@@ -103,7 +104,7 @@ object Future:
103104
var result: Option[T] = None // Not needed if we have full continuations
104105
suspend[T, Unit]: k =>
105106
src.onComplete: x =>
106-
config.scheduler.schedule: () =>
107+
config.scheduler.execute: () =>
107108
result = Some(x)
108109
k.resume()
109110
true // signals to `src` that result `x` was consumed
@@ -124,7 +125,7 @@ object Future:
124125
body(using FutureAsync())
125126
end async
126127

127-
ac.scheduler.schedule: () =>
128+
ac.scheduler.execute: () =>
128129
async:
129130
link()
130131
Async.group:
@@ -198,7 +199,7 @@ class Task[+T](val body: Async ?=> T):
198199

199200
end Task
200201

201-
def add(x: Future[Int], xs: List[Future[Int]])(using Scheduler): Future[Int] =
202+
def add(x: Future[Int], xs: List[Future[Int]])(using ExecutionContext): Future[Int] =
202203
val b = x.zip:
203204
Future:
204205
xs.headOption.toString
@@ -217,6 +218,6 @@ def add(x: Future[Int], xs: List[Future[Int]])(using Scheduler): Future[Int] =
217218

218219
end add
219220

220-
def Main(x: Future[Int], xs: List[Future[Int]])(using Scheduler): Int =
221+
def Main(x: Future[Int], xs: List[Future[Int]])(using ExecutionContext): Int =
221222
Async.blocking(add(x, xs).value)
222223

tests/run/suspend-strawman-2/scheduler.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/run/suspend-strawman-2/simple-futures.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package simpleFutures
33
import scala.collection.mutable.ListBuffer
44
import scala.util.boundary, boundary.Label
55
import runtime.suspend
6-
import concurrent.Scheduler
6+
7+
object Scheduler:
8+
def schedule(task: Runnable): Unit = ???
79

810
trait Async:
911
def await[T](f: Future[T]): T

0 commit comments

Comments
 (0)