@@ -3265,7 +3265,7 @@ trait Observable[+T]
3265
3265
/**
3266
3266
* Returns an Observable that emits the same values as the source observable with the exception of an
3267
3267
* `onError`. An `onError` notification from the source will result in the emission of a
3268
- * [[Notification ]] to the Observable provided as an argument to the `notificationHandler`
3268
+ * [[Throwable ]] to the Observable provided as an argument to the `notificationHandler`
3269
3269
* function. If the Observable returned `onCompletes` or `onErrors` then `retry` will call
3270
3270
* `onCompleted` or `onError` on the child subscription. Otherwise, this Observable will
3271
3271
* resubscribe to the source Observable.
@@ -3276,54 +3276,60 @@ trait Observable[+T]
3276
3276
*
3277
3277
* This retries 3 times, each time incrementing the number of seconds it waits.
3278
3278
*
3279
- * <pre>
3279
+ * @example
3280
+ *
3281
+ * This retries 3 times, each time incrementing the number of seconds it waits.
3282
+ *
3283
+ * {{{
3280
3284
* Observable[String]({ subscriber =>
3281
3285
* println("subscribing")
3282
3286
* subscriber.onError(new RuntimeException("always fails"))
3283
- * }).retryWhen(attempts => {
3284
- * attempts .zipWith(Observable.from(1 to 3))((n , i) => i).flatMap(i => {
3287
+ * }).retryWhen({ throwableObservable =>
3288
+ * throwableObservable .zipWith(Observable.from(1 to 3))((t , i) => i).flatMap(i => {
3285
3289
* println("delay retry by " + i + " second(s)")
3286
3290
* Observable.timer(Duration(i, TimeUnit.SECONDS))
3287
3291
* })
3288
3292
* }).toBlocking.foreach(s => println(s))
3289
- * </pre>
3293
+ * }}}
3290
3294
*
3291
3295
* Output is:
3292
3296
*
3293
- * <pre>
3297
+ * {{{
3294
3298
* subscribing
3295
3299
* delay retry by 1 second(s)
3296
3300
* subscribing
3297
3301
* delay retry by 2 second(s)
3298
3302
* subscribing
3299
3303
* delay retry by 3 second(s)
3300
3304
* subscribing
3301
- * </pre>
3305
+ * }}}
3306
+ *
3302
3307
* <dl>
3303
3308
* <dt><b>Scheduler:</b></dt>
3304
3309
* <dd>`retryWhen` operates by default on the `trampoline` [[Scheduler ]].</dd>
3305
3310
* </dl>
3306
3311
*
3307
- * @param notificationHandler receives an Observable of notifications with which a user can complete or error, aborting the
3312
+ * @param notificationHandler receives an Observable of a Throwable with which a user can complete or error, aborting the
3308
3313
* retry
3309
3314
* @return the source Observable modified with retry logic
3310
3315
* @see <a href="https://github.com/Netflix/RxJava/wiki/Error-Handling-Operators#retrywhen">RxJava Wiki: retryWhen()</a>
3316
+ * @see RxScalaDemo.retryWhenDifferentExceptionsExample for a more intricate example
3311
3317
* @since 0.20
3312
3318
*/
3313
- def retryWhen (notificationHandler : Observable [Notification [ Any ] ] => Observable [Any ]): Observable [T ] = {
3319
+ def retryWhen (notificationHandler : Observable [Throwable ] => Observable [Any ]): Observable [T ] = {
3314
3320
val f : Func1 [_ >: rx.Observable [_ <: rx.Notification [_ <: Any ]], _ <: rx.Observable [_ <: Any ]] =
3315
3321
(jOn : rx.Observable [_ <: rx.Notification [_ <: Any ]]) => {
3316
3322
val on = toScalaObservable[rx.Notification [_ <: Any ]](jOn).map({ jN => toScalaNotification[Any ](jN) })
3317
- notificationHandler(on).asJavaObservable
3323
+ notificationHandler(on.map({ case Notification . OnError (error) => error }) ).asJavaObservable
3318
3324
}
3319
3325
3320
3326
toScalaObservable[T ](asJavaObservable.retryWhen(f))
3321
3327
}
3322
3328
3323
3329
/**
3324
3330
* Returns an Observable that emits the same values as the source observable with the exception of an `onError`.
3325
- * An onError will emit a [[Notification ]] to the observable provided as an argument to the notificationHandler
3326
- * func. If the observable returned `onCompletes` or `onErrors` then retry will call `onCompleted`
3331
+ * An onError will emit a [[Throwable ]] to the Observable provided as an argument to the notificationHandler
3332
+ * func. If the Observable returned `onCompletes` or `onErrors` then retry will call `onCompleted`
3327
3333
* or `onError` on the child subscription. Otherwise, this observable will resubscribe to the source observable, on a particular Scheduler.
3328
3334
* <p>
3329
3335
* <img width="640" height="430" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/retryWhen.f.png" alt="">
@@ -3333,18 +3339,19 @@ trait Observable[+T]
3333
3339
* <dd>you specify which [[Scheduler ]] this operator will use</dd>
3334
3340
* </dl>
3335
3341
*
3336
- * @param notificationHandler receives an Observable of notifications with which a user can complete or error, aborting the
3337
- * retry
3342
+ * @param notificationHandler receives an Observable of a Throwable with which a user can complete or error, aborting
3343
+ * the retry
3338
3344
* @param scheduler the Scheduler on which to subscribe to the source Observable
3339
3345
* @return the source Observable modified with retry logic
3340
3346
* @see <a href="https://github.com/Netflix/RxJava/wiki/Error-Handling-Operators#retrywhen">RxJava Wiki: retryWhen()</a>
3347
+ * @see RxScalaDemo.retryWhenDifferentExceptionsExample for a more intricate example
3341
3348
* @since 0.20
3342
3349
*/
3343
- def retryWhen (notificationHandler : Observable [Notification [ Any ] ] => Observable [Any ], scheduler : Scheduler ): Observable [T ] = {
3350
+ def retryWhen (notificationHandler : Observable [Throwable ] => Observable [Any ], scheduler : Scheduler ): Observable [T ] = {
3344
3351
val f : Func1 [_ >: rx.Observable [_ <: rx.Notification [_ <: Any ]], _ <: rx.Observable [_ <: Any ]] =
3345
3352
(jOn : rx.Observable [_ <: rx.Notification [_ <: Any ]]) => {
3346
3353
val on = toScalaObservable[rx.Notification [_ <: Any ]](jOn).map({ jN => toScalaNotification[Any ](jN) })
3347
- notificationHandler(on).asJavaObservable
3354
+ notificationHandler(on.map({ case Notification . OnError (error) => error }) ).asJavaObservable
3348
3355
}
3349
3356
3350
3357
toScalaObservable[T ](asJavaObservable.retryWhen(f, scheduler))
@@ -3415,7 +3422,7 @@ trait Observable[+T]
3415
3422
/**
3416
3423
* Returns an Observable that emits the same values as the source Observable with the exception of an
3417
3424
* `onCompleted`. An `onCompleted` notification from the source will result in the emission of
3418
- * a [[Notification ]] to the Observable provided as an argument to the `notificationHandler`
3425
+ * a [[scala.Unit ]] to the Observable provided as an argument to the `notificationHandler`
3419
3426
* function. If the Observable returned `onCompletes` or `onErrors` then `repeatWhen` will
3420
3427
* call `onCompleted` or `onError` on the child subscription. Otherwise, this Observable will
3421
3428
* resubscribe to the source Observable, on a particular Scheduler.
@@ -3426,18 +3433,18 @@ trait Observable[+T]
3426
3433
* <dd>you specify which [[Scheduler ]] this operator will use</dd>
3427
3434
* </dl>
3428
3435
*
3429
- * @param notificationHandler receives an Observable of notifications with which a user can complete or error, aborting the repeat.
3436
+ * @param notificationHandler receives an Observable of a Unit with which a user can complete or error, aborting the repeat.
3430
3437
* @param scheduler the Scheduler to emit the items on
3431
3438
* @return the source Observable modified with repeat logic
3432
3439
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#repeatwhen">RxJava Wiki: repeatWhen()</a>
3433
3440
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229428.aspx">MSDN: Observable.Repeat</a>
3434
3441
* @since 0.20
3435
3442
*/
3436
- def repeatWhen (notificationHandler : Observable [Notification [ Any ] ] => Observable [Any ], scheduler : Scheduler ): Observable [T ] = {
3443
+ def repeatWhen (notificationHandler : Observable [Unit ] => Observable [Any ], scheduler : Scheduler ): Observable [T ] = {
3437
3444
val f : Func1 [_ >: rx.Observable [_ <: rx.Notification [_ <: Any ]], _ <: rx.Observable [_ <: Any ]] =
3438
3445
(jOn : rx.Observable [_ <: rx.Notification [_ <: Any ]]) => {
3439
3446
val on = toScalaObservable[rx.Notification [_ <: Any ]](jOn).map({ jN => toScalaNotification[Any ](jN) })
3440
- notificationHandler(on).asJavaObservable
3447
+ notificationHandler(on.map( _ => Unit ) ).asJavaObservable
3441
3448
}
3442
3449
3443
3450
toScalaObservable[T ](asJavaObservable.repeatWhen(f, scheduler))
@@ -3446,28 +3453,57 @@ trait Observable[+T]
3446
3453
/**
3447
3454
* Returns an Observable that emits the same values as the source Observable with the exception of an
3448
3455
* `onCompleted`. An `onCompleted` notification from the source will result in the emission of
3449
- * a [[Notification ]] to the Observable provided as an argument to the `notificationHandler`
3456
+ * a [[scala.Unit ]] to the Observable provided as an argument to the `notificationHandler`
3450
3457
* function. If the Observable returned `onCompletes` or `onErrors` then `repeatWhen` will
3451
3458
* call `onCompleted` or `onError` on the child subscription. Otherwise, this Observable will
3452
3459
* resubscribe to the source observable.
3453
3460
* <p>
3454
3461
* <img width="640" height="430" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/repeatWhen.f.png" alt="">
3462
+ *
3463
+ * @example
3464
+ *
3465
+ * This repeats 3 times, each time incrementing the number of seconds it waits.
3466
+ *
3467
+ * {{{
3468
+ * Observable[String]({ subscriber =>
3469
+ * println("subscribing")
3470
+ * subscriber.onCompleted()
3471
+ * }).repeatWhen({ unitObservable =>
3472
+ * unitObservable.zipWith(Observable.from(1 to 3))((u, i) => i).flatMap(i => {
3473
+ * println("delay repeat by " + i + " second(s)")
3474
+ * Observable.timer(Duration(i, TimeUnit.SECONDS))
3475
+ * })
3476
+ * }).toBlocking.foreach(s => println(s))
3477
+ * }}}
3478
+ *
3479
+ * Output is:
3480
+ *
3481
+ * {{{
3482
+ * subscribing
3483
+ * delay repeat by 1 second(s)
3484
+ * subscribing
3485
+ * delay repeat by 2 second(s)
3486
+ * subscribing
3487
+ * delay repeat by 3 second(s)
3488
+ * subscribing
3489
+ * }}}
3490
+ *
3455
3491
* <dl>
3456
3492
* <dt><b>Scheduler:</b></dt>
3457
3493
* <dd>`repeatWhen` operates by default on the `trampoline` [[Scheduler ]].</dd>
3458
3494
* </dl>
3459
3495
*
3460
- * @param notificationHandler receives an Observable of notifications with which a user can complete or error, aborting the repeat.
3496
+ * @param notificationHandler receives an Observable of a Unit with which a user can complete or error, aborting the repeat.
3461
3497
* @return the source Observable modified with repeat logic
3462
3498
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#repeatwhen">RxJava Wiki: repeatWhen()</a>
3463
3499
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229428.aspx">MSDN: Observable.Repeat</a>
3464
3500
* @since 0.20
3465
3501
*/
3466
- def repeatWhen (notificationHandler : Observable [Notification [ Any ] ] => Observable [Any ]): Observable [T ] = {
3502
+ def repeatWhen (notificationHandler : Observable [Unit ] => Observable [Any ]): Observable [T ] = {
3467
3503
val f : Func1 [_ >: rx.Observable [_ <: rx.Notification [_ <: Any ]], _ <: rx.Observable [_ <: Any ]] =
3468
3504
(jOn : rx.Observable [_ <: rx.Notification [_ <: Any ]]) => {
3469
3505
val on = toScalaObservable[rx.Notification [_ <: Any ]](jOn).map({ jN => toScalaNotification[Any ](jN) })
3470
- notificationHandler(on).asJavaObservable
3506
+ notificationHandler(on.map( _ => Unit ) ).asJavaObservable
3471
3507
}
3472
3508
3473
3509
toScalaObservable[T ](asJavaObservable.repeatWhen(f))
0 commit comments