File tree 1 file changed +2
-22
lines changed
tests/run/suspend-strawman-2
1 file changed +2
-22
lines changed Original file line number Diff line number Diff line change @@ -97,33 +97,13 @@ object SyncChannel:
97
97
98
98
end SyncChannel
99
99
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
-
120
100
def TestChannel (using Scheduler ) =
121
101
val c = SyncChannel [Option [Int ]]()
122
- Coroutine :
102
+ Future :
123
103
for i <- 0 to 100 do
124
104
c.send(Some (i))
125
105
c.send(None )
126
- Coroutine :
106
+ Future :
127
107
var sum = 0
128
108
def loop (): Unit =
129
109
c.read() match
You can’t perform that action at this time.
0 commit comments