@@ -285,30 +285,23 @@ private[concurrent] final object Promise {
285
285
}
286
286
287
287
// IMPORTANT: Noop should never be passed in here, neither as left OR as right
288
- @ tailrec private [this ] final def concatCallbacks (left : Callbacks [T ], right : Callbacks [T ]): Callbacks [T ] = {
289
- if (left.isInstanceOf [Transformation [T ,_]]) new ManyCallbacks [T ](left, right)
288
+ @ tailrec private [this ] final def concatCallbacks (left : Callbacks [T ], right : Callbacks [T ]): Callbacks [T ] =
289
+ if (left.isInstanceOf [Transformation [T ,_]]) new ManyCallbacks [T ](left. asInstanceOf [ Transformation [ T ,_]] , right)
290
290
else /* if (left.isInstanceOf[ManyCallbacks[T]) */ { // This should only happen when linking
291
291
val m = left.asInstanceOf [ManyCallbacks [T ]]
292
- concatCallbacks(m.last , new ManyCallbacks (m.first, right))
292
+ concatCallbacks(m.rest , new ManyCallbacks (m.first, right))
293
293
}
294
- }
295
294
296
- // IMPORTANT: Noop should not be passed in here
295
+ // IMPORTANT: Noop should not be passed in here, `callbacks` cannot be null
297
296
@ tailrec
298
- private [this ] final def submitWithValue (callbacks : Callbacks [T ],
299
- resolved : Try [T ],
300
- deferred : List [Callbacks [T ]] = Nil ): Unit = {
301
- callbacks match {
302
- case m : ManyCallbacks [T ] =>
303
- submitWithValue(m.first, resolved, m.last :: deferred)
304
- case t : Transformation [T , _] =>
305
- t.submitWithValue(resolved)
306
- deferred match {
307
- case head :: tail => submitWithValue(head, resolved, tail)
308
- case Nil => // ignore
309
- }
297
+ private [this ] final def submitWithValue (callbacks : Callbacks [T ], resolved : Try [T ]): Unit =
298
+ if (callbacks.isInstanceOf [ManyCallbacks [T ]]) {
299
+ val m : ManyCallbacks [T ] = callbacks.asInstanceOf [ManyCallbacks [T ]]
300
+ m.first.submitWithValue(resolved)
301
+ submitWithValue(m.rest, resolved)
302
+ } else {
303
+ callbacks.asInstanceOf [Transformation [T , _]].submitWithValue(resolved)
310
304
}
311
- }
312
305
313
306
/** Link this promise to the root of another promise.
314
307
*/
@@ -352,7 +345,7 @@ private[concurrent] final object Promise {
352
345
sealed trait Callbacks [- T ] {
353
346
}
354
347
355
- final class ManyCallbacks [- T ](final val first : Callbacks [ T ], final val last : Callbacks [T ]) extends Callbacks [T ] {
348
+ final class ManyCallbacks [- T ](final val first : Transformation [ T ,_ ], final val rest : Callbacks [T ]) extends Callbacks [T ] {
356
349
// NOTE: This does grow the stack for *linked* callbacks which are transported across the links,
357
350
// these should normally be rather flat.
358
351
override final def toString : String = " ManyCallbacks"
0 commit comments