-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Thorium/more-functions
Added more functions, and `rxquery { ... }`
- Loading branch information
Showing
8 changed files
with
238 additions
and
37 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
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
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,53 @@ | ||
namespace FSharp.Control.R3.Tests | ||
|
||
open System | ||
open System.Threading.Tasks | ||
open FSharp.Control.R3.Async | ||
open FSharp.Control.R3.Observable.Builders | ||
open Microsoft.VisualStudio.TestTools.UnitTesting | ||
open Swensen.Unquote | ||
|
||
[<TestClass>] | ||
type BuilderTests () = | ||
|
||
[<TestMethod>] | ||
member _.``Test builder rxquery`` () = | ||
|
||
let mutable hasvisited = false | ||
use r3Bus = new R3.Subject<int> () | ||
|
||
let interesting = rxquery { | ||
for i in r3Bus do | ||
where (i % 2 = 0) | ||
select i | ||
|
||
// Same as: | ||
// if i % 2 = 0 then | ||
// yield i | ||
|
||
} | ||
|
||
// No-one listens yet (vs R3.ReplaySubject<int> | ||
r3Bus.OnNext 2 | ||
|
||
use subscription = | ||
R3.ObservableExtensions.SubscribeAwait ( | ||
interesting, | ||
fun i cancellationToken -> | ||
task { | ||
// Listen events | ||
|
||
hasvisited <- true | ||
|
||
Assert.AreEqual<int> (4, i) | ||
|
||
return () | ||
} | ||
|> System.Threading.Tasks.ValueTask | ||
) | ||
|
||
// Publish some events, "4" should be heard | ||
[ 3..5 ] |> List.iter r3Bus.OnNext | ||
// Note: Query will not be awaited, that's why delay. | ||
System.Threading.Thread.Sleep 300 | ||
Assert.AreEqual<bool> (true, hasvisited) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace FSharp.Control.R3.Tests | ||
|
||
open System | ||
open System.Threading.Tasks | ||
open FSharp.Control.R3.Async | ||
open Microsoft.VisualStudio.TestTools.UnitTesting | ||
open Swensen.Unquote | ||
|
||
[<TestClass>] | ||
type ObservableTests () = | ||
|
||
[<TestMethod>] | ||
member _.``Test length`` () : Task = | ||
|
||
async { | ||
use r3Bus = new R3.Subject<int> () | ||
|
||
r3Bus.OnNext 1 | ||
|
||
let lengthObs = Observable.length r3Bus | ||
|
||
r3Bus.OnNext 2 | ||
r3Bus.OnNext 3 | ||
r3Bus.OnCompleted (R3.Result.Success) | ||
|
||
let! res = lengthObs | ||
|
||
Assert.AreEqual<int> (0, res) | ||
|
||
} | ||
|> Async.StartImmediateAsTask | ||
:> Task | ||
|
||
|
||
[<TestMethod>] | ||
member _.``Test filter`` () = | ||
|
||
let mutable hasvisited = false | ||
use r3Bus = new R3.Subject<int> () | ||
let interesting = | ||
r3Bus | ||
|> FSharp.Control.R3.Observable.filter (fun x -> x % 2 = 0) | ||
|
||
// No-one listens yet (vs R3.ReplaySubject<int> | ||
r3Bus.OnNext 2 | ||
|
||
use subscription = | ||
R3.ObservableExtensions.SubscribeAwait ( | ||
interesting, | ||
fun i cancellationToken -> | ||
task { | ||
// Listen events | ||
|
||
hasvisited <- true | ||
|
||
Assert.AreEqual<int> (4, i) | ||
|
||
return () | ||
} | ||
|> System.Threading.Tasks.ValueTask | ||
) | ||
|
||
// Publish some events, "4" should be heard | ||
[ 3..5 ] |> List.iter r3Bus.OnNext | ||
Assert.AreEqual<bool> (true, hasvisited) |
This file was deleted.
Oops, something went wrong.