Skip to content

Commit 294bf1d

Browse files
committed
Use Futures instead of Coroutines
Even for a coroutine we want to observe normal or anormal termination. In that sense a Coroutine is really nothing but a Future[Unit].
1 parent c810bf2 commit 294bf1d

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,13 @@ object SyncChannel:
9797

9898
end SyncChannel
9999

100-
/** A simplistic coroutine. Error handling is still missing, */
101-
class Coroutine(body: Async ?=> Unit)(using scheduler: Scheduler) extends Cancellable:
102-
private var children: mutable.ListBuffer[Cancellable] = mutable.ListBuffer()
103-
@volatile var cancelled = false
104-
105-
def cancel() =
106-
cancelled = true
107-
synchronized(children).foreach(_.cancel())
108-
109-
def addChild(child: Cancellable) = synchronized:
110-
children += child
111-
112-
boundary [Unit]:
113-
given Async = new Async.Impl(this, scheduler):
114-
def checkCancellation() =
115-
if cancelled then throw new CancellationException()
116-
try body
117-
catch case ex: CancellationException => ()
118-
end Coroutine
119-
120100
def TestChannel(using Scheduler) =
121101
val c = SyncChannel[Option[Int]]()
122-
Coroutine:
102+
Future:
123103
for i <- 0 to 100 do
124104
c.send(Some(i))
125105
c.send(None)
126-
Coroutine:
106+
Future:
127107
var sum = 0
128108
def loop(): Unit =
129109
c.read() match

0 commit comments

Comments
 (0)