Hi.

When I run your test program (under Linux), the messages don't appear all at 
once.

One small suggestion for improvement: The application is not very response, 
because recv() waits until something is received. You can use tryRecv() in 
combination with app.sleep() instead.

> 
>     import nigui
>     import std/strformat
>     import os
>     
>     var ch: Channel[string]
>     
>     proc messaggiInTextArea(primoMsg: string) {.thread.} =
>         ch.send(primoMsg)
>         for x in 1..10:
>             ch.send(&"Messaggio n°: {x}")
>             sleep(1000)
>         ch.send("Dopo il ciclo for")
>         ch.send("")
>     
>     app.init()
>     
>     var window = newWindow("Test Thread")
>     
>     var container = newLayoutContainer(Layout_Vertical)
>     window.add(container)
>     
>     var buttonSave = newButton("Esegui test")
>     container.add(buttonSave)
>     
>     var areaMessaggi = newTextArea()
>     areaMessaggi.editable=false
>     container.add(areaMessaggi)
>     
>     buttonSave.onClick = proc(event: ClickEvent) =
>         var th: Thread[string]
>         areaMessaggi.text=""
>         areaMessaggi.addLine("Inizia il test: prima della chiamata alla 
> procedura")
>         ch.open()
>         createThread(th, messaggiInTextArea, "Prima chiamata dalla proc")
>         while true:
>             let (received, msg) = ch.tryRecv()
>             if received:
>               if msg == "":
>                   break
>               areaMessaggi.addLine(msg)
>             else:
>               app.sleep(50)
>         joinThreads(th)
>         ch.close()
>         areaMessaggi.addLine("Fine del test: dopo la chiamata alla procedura")
>     
>     
>     window.show()
>     
>     app.run()
>     
>     
>     Run

Reply via email to