Skip to content

Instantly share code, notes, and snippets.

@isaksky

isaksky/Output.txt

Created Apr 2, 2018
Embed
What would you like to do?
Gjallarhorn
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
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
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