generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rx): add repeat operator (#192)
- Loading branch information
1 parent
9984e1b
commit 8ddd6db
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package rx_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fortytw2/leaktest" | ||
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok | ||
"github.com/snivilised/lorax/rx" | ||
) | ||
|
||
var _ = Describe("Observable operator", func() { | ||
Context("Retry", func() { | ||
When("principle", func() { | ||
It("🧪 should: retry", func() { | ||
// rxgo: Test_Observable_Retry | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
i := 0 | ||
obs := rx.Defer([]rx.Producer[int]{func(_ context.Context, next chan<- rx.Item[int]) { | ||
next <- rx.Of(1) | ||
next <- rx.Of(2) | ||
if i == 2 { | ||
next <- rx.Of(3) | ||
} else { | ||
i++ | ||
next <- rx.Error[int](errFoo) | ||
} | ||
}}).Retry(3, func(_ error) bool { | ||
return true | ||
}) | ||
rx.Assert(ctx, obs, | ||
rx.HasItems[int]{ | ||
Expected: []int{1, 2, 1, 2, 1, 2, 3}, | ||
}, | ||
rx.HasNoError[int]{}, | ||
) | ||
}) | ||
}) | ||
|
||
Context("Errors", func() { | ||
When("retry error", func() { | ||
It("🧪 should: retry", func() { | ||
// rxgo: Test_Observable_Retry_Error_ShouldRetry | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
obs := rx.Defer([]rx.Producer[int]{func(_ context.Context, next chan<- rx.Item[int]) { | ||
next <- rx.Of(1) | ||
next <- rx.Of(2) | ||
next <- rx.Error[int](errFoo) | ||
}}).Retry(3, func(_ error) bool { | ||
return true | ||
}) | ||
rx.Assert(ctx, obs, rx.HasItems[int]{ | ||
Expected: []int{1, 2, 1, 2, 1, 2, 1, 2}, | ||
}, rx.HasError[int]{ | ||
Expected: []error{errFoo}, | ||
}) | ||
}) | ||
}) | ||
|
||
When("retry error", func() { | ||
It("🧪 should: not retry", func() { | ||
// rxgo: Test_Observable_Retry_Error_ShouldNotRetry | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
obs := rx.Defer([]rx.Producer[int]{func(_ context.Context, next chan<- rx.Item[int]) { | ||
next <- rx.Of(1) | ||
next <- rx.Of(2) | ||
next <- rx.Error[int](errFoo) | ||
}}).Retry(3, func(_ error) bool { | ||
return false | ||
}) | ||
rx.Assert(ctx, obs, rx.HasItems[int]{ | ||
Expected: []int{1, 2}, | ||
}, rx.HasError[int]{ | ||
Expected: []error{errFoo}, | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters