@@ -6,6 +6,7 @@ open FSharp.Control
66open Fable.Python
77open Fable.Python .TkInter
88open Fable.Python .Queue
9+ open Fable.Python .AsyncIO
910
1011type Msg =
1112 | Place of label : Label * x : int * y : int
@@ -30,7 +31,6 @@ let workerAsync (mb: MailboxProcessor<Event>) =
3031 messageLoop ()
3132
3233let agent = MailboxProcessor< TkInter.Event>. Start ( workerAsync)
33-
3434let frame = Frame( root, width = 800 , height = 600 , bg = " white" )
3535frame.bind ( " <Motion>" , agent.Post) |> ignore
3636frame.pack ()
@@ -47,7 +47,7 @@ let stream =
4747let sink ( ev : Notification < Label * int * int >) =
4848 async {
4949 match ev with
50- | OnNext ( label, x, y) -> queue.put ( Place ( label , x, y) )
50+ | OnNext ( label, x, y) -> label.place ( x, y)
5151 | OnError ( err) -> printfn $" Stream Error: {err}"
5252 | _ -> printfn " Stream Completed!"
5353 }
@@ -56,22 +56,11 @@ let mainAsync =
5656 async {
5757 use! disposable = stream.SubscribeAsync( sink)
5858
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+ ()
7262
73- root.after ( 1 , update)
74- root.mainloop ()
63+ do ! Async.AwaitTask( asyncio.create_ task( asyncio.sleep( 0.005 )))
7564 }
7665
7766[<EntryPoint>]
0 commit comments