@@ -53,14 +53,22 @@ object Async:
53
53
checkCancellation()
54
54
src.poll().getOrElse:
55
55
try
56
- var result : Option [T ] = None
56
+ var result : Option [T ] = None // Not needed if we have full continuations
57
57
suspend[T , Unit ]: k =>
58
58
src.onComplete: x =>
59
59
scheduler.schedule: () =>
60
60
result = Some (x)
61
61
k.resume()
62
62
true // signals to `src` that result `x` was consumed
63
63
result.get
64
+ /* With full continuations, the try block can be written more simply as follows:
65
+
66
+ suspend[T, Unit]: k =>
67
+ src.onComplete: x =>
68
+ scheduler.schedule: () =>
69
+ k.resume(x)
70
+ true
71
+ */
64
72
finally checkCancellation()
65
73
66
74
end Impl
@@ -109,11 +117,6 @@ object Async:
109
117
*/
110
118
abstract case class ForwardingListener [T ](src : Source [? ], continue : Listener [? ]) extends Listener [T ]
111
119
112
- /** A listener for values that are processed directly in an async block.
113
- * Closures of type `T => Boolean` can be SAM converted to this type.
114
- */
115
- abstract case class FinalListener [T ](apply : T => Boolean ) extends Listener [T ]
116
-
117
120
/** An asynchronous data source. Sources can be persistent or ephemeral.
118
121
* A persistent source will always pass same data to calls of `poll and `onComplete`.
119
122
* An ephememral source can pass new data in every call.
@@ -158,7 +161,7 @@ object Async:
158
161
/** Add `k` to the listener set of this source */
159
162
protected def addListener (k : Listener [T ]): Unit
160
163
161
- def onComplete (k : Listener [T ]): Unit = synchronized :
164
+ def onComplete (k : Listener [T ]): Unit =
162
165
if ! poll(k) then addListener(k)
163
166
164
167
end OriginalSource
@@ -232,8 +235,8 @@ object Async:
232
235
/** If left (respectively, right) source succeeds with `x`, pass `Left(x)`,
233
236
* (respectively, Right(x)) on to the continuation.
234
237
*/
235
- def either [T , U ](src1 : Source [T ], src2 : Source [U ]): Source [Either [T , U ]] =
236
- race[ Either [ T , U ]] (src1.map(Left (_)), src2.map(Right (_)))
238
+ def either [T1 , T2 ](src1 : Source [T1 ], src2 : Source [T2 ]): Source [Either [T1 , T2 ]] =
239
+ race(src1.map(Left (_)), src2.map(Right (_)))
237
240
238
241
end Async
239
242
0 commit comments