@@ -7,13 +7,6 @@ import (
7
7
"github.com/cenkalti/backoff/v4"
8
8
)
9
9
10
- // func isZero[T any](limit T) bool {
11
- // val := reflect.ValueOf(limit).Interface()
12
- // zero := reflect.Zero(reflect.TypeOf(limit)).Interface()
13
-
14
- // return val != zero
15
- // }
16
-
17
10
// All determines whether all items emitted by an Observable meet some criteria.
18
11
func (o * ObservableImpl [T ]) All (predicate Predicate [T ], opts ... Option [T ]) Single [T ] {
19
12
const (
@@ -1359,6 +1352,115 @@ func (o *ObservableImpl[T]) Observe(opts ...Option[T]) <-chan Item[T] {
1359
1352
return o .iterable .Observe (opts ... )
1360
1353
}
1361
1354
1355
+ // OnErrorResumeNext instructs an Observable to pass control to another Observable rather than invoking
1356
+ // onError if it encounters an error.
1357
+ func (o * ObservableImpl [T ]) OnErrorResumeNext (resumeSequence ErrorToObservable [T ], opts ... Option [T ]) Observable [T ] {
1358
+ const (
1359
+ forceSeq = true
1360
+ bypassGather = false
1361
+ )
1362
+
1363
+ return observable (o .parent , o , func () operator [T ] {
1364
+ return & onErrorResumeNextOperator [T ]{
1365
+ resumeSequence : resumeSequence ,
1366
+ }
1367
+ }, forceSeq , bypassGather , opts ... )
1368
+ }
1369
+
1370
+ type onErrorResumeNextOperator [T any ] struct {
1371
+ resumeSequence ErrorToObservable [T ]
1372
+ }
1373
+
1374
+ func (op * onErrorResumeNextOperator [T ]) next (ctx context.Context , item Item [T ],
1375
+ dst chan <- Item [T ], _ operatorOptions [T ]) {
1376
+ item .SendContext (ctx , dst )
1377
+ }
1378
+
1379
+ func (op * onErrorResumeNextOperator [T ]) err (_ context.Context , item Item [T ],
1380
+ _ chan <- Item [T ], operatorOptions operatorOptions [T ],
1381
+ ) {
1382
+ operatorOptions .resetIterable (op .resumeSequence (item .E ))
1383
+ }
1384
+
1385
+ func (op * onErrorResumeNextOperator [T ]) end (_ context.Context , _ chan <- Item [T ]) {
1386
+ }
1387
+
1388
+ func (op * onErrorResumeNextOperator [T ]) gatherNext (_ context.Context , _ Item [T ],
1389
+ _ chan <- Item [T ], _ operatorOptions [T ]) {
1390
+ }
1391
+
1392
+ func (o * ObservableImpl [T ]) OnErrorReturn (resumeFunc ErrorFunc [T ], opts ... Option [T ]) Observable [T ] {
1393
+ const (
1394
+ forceSeq = true
1395
+ bypassGather = false
1396
+ )
1397
+
1398
+ return observable (o .parent , o , func () operator [T ] {
1399
+ return & onErrorReturnOperator [T ]{
1400
+ resumeFunc : resumeFunc ,
1401
+ }
1402
+ }, forceSeq , bypassGather , opts ... )
1403
+ }
1404
+
1405
+ type onErrorReturnOperator [T any ] struct {
1406
+ resumeFunc ErrorFunc [T ]
1407
+ }
1408
+
1409
+ func (op * onErrorReturnOperator [T ]) next (ctx context.Context , item Item [T ],
1410
+ dst chan <- Item [T ], _ operatorOptions [T ]) {
1411
+ item .SendContext (ctx , dst )
1412
+ }
1413
+
1414
+ func (op * onErrorReturnOperator [T ]) err (ctx context.Context , item Item [T ],
1415
+ dst chan <- Item [T ], _ operatorOptions [T ],
1416
+ ) {
1417
+ Of [T ](op .resumeFunc (item .E )).SendContext (ctx , dst )
1418
+ }
1419
+
1420
+ func (op * onErrorReturnOperator [T ]) end (_ context.Context , _ chan <- Item [T ]) {
1421
+ }
1422
+
1423
+ func (op * onErrorReturnOperator [T ]) gatherNext (_ context.Context , _ Item [T ],
1424
+ _ chan <- Item [T ], _ operatorOptions [T ]) {
1425
+ }
1426
+
1427
+ func (o * ObservableImpl [T ]) OnErrorReturnItem (resume T , opts ... Option [T ]) Observable [T ] {
1428
+ const (
1429
+ forceSeq = true
1430
+ bypassGather = false
1431
+ )
1432
+
1433
+ return observable (o .parent , o , func () operator [T ] {
1434
+ return & onErrorReturnItemOperator [T ]{
1435
+ resume : resume ,
1436
+ }
1437
+ }, true , false , opts ... )
1438
+ }
1439
+
1440
+ type onErrorReturnItemOperator [T any ] struct {
1441
+ resume T
1442
+ }
1443
+
1444
+ func (op * onErrorReturnItemOperator [T ]) next (ctx context.Context , item Item [T ],
1445
+ dst chan <- Item [T ], _ operatorOptions [T ],
1446
+ ) {
1447
+ item .SendContext (ctx , dst )
1448
+ }
1449
+
1450
+ func (op * onErrorReturnItemOperator [T ]) err (ctx context.Context , _ Item [T ],
1451
+ dst chan <- Item [T ], _ operatorOptions [T ],
1452
+ ) {
1453
+ Of (op .resume ).SendContext (ctx , dst )
1454
+ }
1455
+
1456
+ func (op * onErrorReturnItemOperator [T ]) end (_ context.Context , _ chan <- Item [T ]) {
1457
+ }
1458
+
1459
+ func (op * onErrorReturnItemOperator [T ]) gatherNext (_ context.Context , _ Item [T ],
1460
+ _ chan <- Item [T ], _ operatorOptions [T ],
1461
+ ) {
1462
+ }
1463
+
1362
1464
// ToSlice collects all items from an Observable and emit them in a slice and
1363
1465
// an optional error. Cannot be run in parallel.
1364
1466
func (o * ObservableImpl [T ]) ToSlice (initialCapacity int , opts ... Option [T ]) ([]Item [T ], error ) {
0 commit comments