@@ -6,6 +6,7 @@ open FSharp.Control
6
6
open Fable.Python
7
7
open Fable.Python .TkInter
8
8
open Fable.Python .Queue
9
+ open Fable.Python .AsyncIO
9
10
10
11
type Msg =
11
12
| Place of label : Label * x : int * y : int
@@ -30,7 +31,6 @@ let workerAsync (mb: MailboxProcessor<Event>) =
30
31
messageLoop ()
31
32
32
33
let agent = MailboxProcessor< TkInter.Event>. Start ( workerAsync)
33
-
34
34
let frame = Frame( root, width = 800 , height = 600 , bg = " white" )
35
35
frame.bind ( " <Motion>" , agent.Post) |> ignore
36
36
frame.pack ()
@@ -47,7 +47,7 @@ let stream =
47
47
let sink ( ev : Notification < Label * int * int >) =
48
48
async {
49
49
match ev with
50
- | OnNext ( label, x, y) -> queue.put ( Place ( label , x, y) )
50
+ | OnNext ( label, x, y) -> label.place ( x, y)
51
51
| OnError ( err) -> printfn $" Stream Error: {err}"
52
52
| _ -> printfn " Stream Completed!"
53
53
}
@@ -56,22 +56,11 @@ let mainAsync =
56
56
async {
57
57
use! disposable = stream.SubscribeAsync( sink)
58
58
59
- let rec update () =
60
- let size = queue.qsize ()
61
-
62
- for _ in 1 .. size do
63
- let msg = queue.get ( false )
64
-
65
- match msg with
66
- | Place ( label, x, y) -> label.place ( x, y)
67
- | _ -> ()
68
-
69
- match size with
70
- | n when n > 0 -> root.after ( 1 , update)
71
- | _ -> root.after ( 10 , update)
59
+ while true do
60
+ while root.dooneevent( int Flags.DONT_ WAIT) do
61
+ ()
72
62
73
- root.after ( 1 , update)
74
- root.mainloop ()
63
+ do ! Async.AwaitTask( asyncio.create_ task( asyncio.sleep( 0.005 )))
75
64
}
76
65
77
66
[<EntryPoint>]
0 commit comments