-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Replay subject #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,4 +113,61 @@ let tests = testList "Subject Tests" [ | |
| Expect.equal actual1 expected1 "Should be equal" | ||
| Expect.equal actual2 expected2 "Should be equal" | ||
| } | ||
|
|
||
| testAsync "Test replay subject broadcasts last 2 values when second observer subscribes late" { | ||
| let (dispatch, stream) = AsyncRx.replaySubject 2 | ||
| let obv1 = TestObserver<_>() | ||
| let obv2 = TestObserver<_>() | ||
|
|
||
| let! _ = stream.SubscribeAsync(obv1) | ||
|
|
||
| do! dispatch.OnNextAsync 'a' | ||
| do! dispatch.OnNextAsync 'b' | ||
| do! dispatch.OnNextAsync 'c' | ||
|
|
||
| // TODO: How should I be yielding here so that obv1.Notifications is populated? | ||
| // (I specifically don't want to emit a completion.) | ||
| do! Async.Sleep 1_000 | ||
|
Comment on lines
+128
to
+130
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dbrattli is there a better way to ensure the value is yielded without using
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have a look, but currently on vacation so might take a few days 😬 |
||
|
|
||
| let! _ = stream.SubscribeAsync(obv2) | ||
|
|
||
| do! Async.Sleep 1_000 | ||
|
|
||
| let actual1 = obv1.Notifications |> Seq.toList | ||
| let expected1 = [ OnNext 'a'; OnNext 'b'; OnNext 'c' ] | ||
| let actual2 = obv2.Notifications |> Seq.toList | ||
| let expected2 = [ OnNext 'b'; OnNext 'c' ] | ||
|
|
||
| Expect.equal actual1 expected1 "Should be equal" | ||
| Expect.equal actual2 expected2 "Should be equal" | ||
| } | ||
|
|
||
| // Behaviour like RxJS. | ||
| // https://github.com/ReactiveX/rxjs/blob/9aa16a9e1dfe73fd6c6ed4084e96d22847b63f9b/spec/subjects/ReplaySubject-spec.ts#L149-L171 | ||
| testAsync "Test replay subject broadcasts last 2 values when second observer subscribes late after completed" { | ||
| let (dispatch, stream) = AsyncRx.replaySubject 2 | ||
| let obv1 = TestObserver<_>() | ||
| let obv2 = TestObserver<_>() | ||
|
|
||
| let! _ = stream.SubscribeAsync(obv1) | ||
|
|
||
| do! dispatch.OnNextAsync 'a' | ||
| do! dispatch.OnNextAsync 'b' | ||
| do! dispatch.OnNextAsync 'c' | ||
| do! dispatch.OnCompletedAsync() | ||
|
|
||
| do! obv1.AwaitIgnore() | ||
|
|
||
| let! _ = stream.SubscribeAsync(obv2) | ||
|
|
||
| do! obv2.AwaitIgnore() | ||
|
|
||
| let actual1 = obv1.Notifications |> Seq.toList | ||
| let expected1 = [ OnNext 'a'; OnNext 'b'; OnNext 'c'; OnCompleted ] | ||
| let actual2 = obv2.Notifications |> Seq.toList | ||
| let expected2 = [ OnNext 'b'; OnNext 'c'; OnCompleted ] | ||
|
|
||
| Expect.equal actual1 expected1 "Should be equal" | ||
| Expect.equal actual2 expected2 "Should be equal" | ||
| } | ||
| ] | ||
Uh oh!
There was an error while loading. Please reload this page.