Created
April 2, 2018 19:58
-
-
Save isaksky/acbf390c8804f1fcb638b3517598accf to your computer and use it in GitHub Desktop.
Gjallarhorn
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
Creating signal... | |
A dependency has changed. Called from thread ID 1 | |
Setting m1... | |
Sleeping 200 ms | |
A dependency has changed. Called from thread ID 3 | |
Signal value is now 4. thread ID: 3 | |
Signal value is now 4. thread ID: 4 | |
Thread awake again | |
Setting m2... | |
Finished | |
A dependency has changed. Called from thread ID 5 | |
Signal value is now 5. thread ID: 5 | |
Signal value is now 5. thread ID: 3 |
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
open Gjallarhorn | |
open System.Threading | |
[<EntryPoint>] | |
let main argv = | |
let m1 = Mutable.create 1L | |
let m2 = Mutable.create 2L | |
let sync_ctx = System.Threading.SynchronizationContext() | |
printfn "Creating signal..." | |
let signal = | |
(m1, m2) | |
||> Signal.map2 | |
(fun a b -> | |
printfn "A dependency has changed. Called from thread ID %d" (Thread.CurrentThread.ManagedThreadId) | |
a + b) | |
|> Signal.observeOn sync_ctx | |
use _sub = signal.Subscribe (fun res -> printfn "Signal value is now %d. thread ID: %d" res (Thread.CurrentThread.ManagedThreadId)) | |
printfn "Setting m1..." | |
m1.Value <- 2L | |
printfn "Sleeping 200 ms" | |
System.Threading.Thread.Sleep(200) | |
printfn "Thread awake again" | |
printfn "Setting m2..." | |
m2.Value <- 3L | |
printfn "Finished" | |
System.Console.ReadLine() |> ignore | |
0 |
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
Seems like there are 2 more subscription messages than expected (line 7 and line 13 of the output). | |
They go away if line 18 of the code is removed. | |
Is this expected? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment