|
Pages: [1]
|
 |
|
Author
|
Topic: events flow (Read 583 times)
|
|
GregP
|
Hi, I'm building an event driven application. Some events are triggered by the user, some other are triggered by face objects itself as they are assigned a rate value so they are refreshed. So, let's say event1 is triggered and the code for event1 is being interpreted. Now, let's say event2 is triggered but we can assume that event1 is not completed. My question is: how does it work? For example: Can the code for event2 be interpreted while event1 is not yet completed? I'm looking for a general explanation on how these events are handled by the interpreter, and, as a result, if external library functions I'm building need to be reentrant. Thanks, GreG
|
|
|
|
|
Logged
|
|
|
|
|
btiffin
|
Try this; rebol [] view layout [button "test" [loop 1000000 [find "abcdefghijk" "cde" wait] print "done"] box rate 1 feel [ engage: func [f a e] [ if a = 'time [ print ["timer in feel" now/precise] ] ] ] ] You might have to crank the loop to get more than one second delay - I'm on an old box and the loop takes about 4 seconds. The timers are not queued ... just forgotten it seems. (There is no flurry of 1 second timer prints after hitting the button on 2.7.6). P.S. I have no clue what I'm talking about ... but I tried this and it seems to look like event2 would not get processed. (At least with timers ... ports and wait may be different) I may well be missing some critical option setting to get this to work properly. After that experiment, try this and tweak the repeat and modulo test values. I'm seeing strange. But please don't take what I'm saying as gospel, I'm just playing. rebol [] view layout [button "test" [repeat i 1000000 [ find "abcdefghijk" "cde" if zero? modulo i 100000 [wait 0 prin i] ] print "done"] box rate 1 feel [ engage: func [f a e] [ if a = 'time [ print ["fire by feel" now/precise] ] ] ] ] This all changes with REBOL release 3 as well. Again. I'm not the expert and probably should have left this post alone Cheers
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
R2 is not multithreaded. If you are doing any code, no event processing can occur. Event are only processed inside the WAIT function.
|
|
|
|
|
Logged
|
|
|
|
|
GregP
|
Thanks bitffin and Gabriele, So, if code main is idle, then any event can be processed. Now, what if event1 code has a wait: can event2 be interpreted? Is there a stack of events or are they lost? With some tests I did like bitffin, I sometimes reach an overflow. Wondering if it is a stack overflow. GreG
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
Yes, if you have a wait inside the event handler, other events can be processed. But, be very careful with things like that. You can easily get into problems.
Events are queued so they are not lost.
|
|
|
|
|
Logged
|
|
|
|
|
Philippe
|
During the last DevCon in Paris, françois Jouen (aka ldci) has shown a piece of code wich simulate multithreadind. I put an example below : ; workspace pic-size: 270x240 pic: make image! pic-size max-space: 225
; definition of the function creating a pixel plot: func [image x y color] [ pixel: to-pair compose[(x) (y)] ; position of pixel poke image pixel color ; place le pixel avec la couleur ]
; -------- vert-line: func ["draw a vertical line" face x [integer!] y1 "top y coordinate (lesser value) " [integer!] y2 "bottom y coordinate (greater value)" [integer!] color "line color" /local dz z t ][ if y1 > y2 [ t: y1 y1: y2 y2: t ] ; simple clipping if x < 1 [exit] ; left edge if x > face/size/x [exit] ; right edge if y1 < 1 [y1: 1] ; top edge if y2 > face/size/y [y2: face/size/y] ; bottom edge z: (y1 - 1) * face/size/x + x ; first poke position dz: face/size/x ; difference to next poke positon ;print rejoin ["z: " z tab "dz: " dz tab "loop " y2 - y1 + 1 ] loop y2 - y1 + 1 [ poke face z color z: dz + z ] exit ] ; end of func vertical line
;------- definition layout ---------- mwin: layout [ across at 5x5 visu: image pic with [ rate: none feel/engage: func [face action event] [ if action = 'time [ face/show-image face]] ; end of feel
show-image: func [f] [ { f is a face} x: x + 1 if x > f/size/x [ x: 0 f/image/rgb: black ] y: random maxi vert-line pic x y face/size/y green + 50 ;plot pic x y random 255.255.255 show f ] ; end of Show-image ] ; end of with visu
at 5x250 timer: info 110 with [ rate: none feel/engage: func [face action event] [ if action = 'time [ face/show-time face]] show-time: func [face][ face/text: join "Il est " now/time/precise show face ] ; end of show-time
] ; end of with timer
; the slider sl: slider 100x20 [ maxi: to-integer sl/data * max-space slt/text: maxi show slt ]
; field text : "maxi" slt: info 30 to-string max-space white font [ name: "Courrier" size: 10 color: red]
at 5x290 btn-enter 80x20 "Start" [ maxi: max-space x: 0 visu/rate: 100 timer/rate: 100 show [visu timer] ] ; start main header
btn-help 80x20 "stop" [ visu/rate: timer/rate: none show [visu timer] ] ; stop main thread
btn-cancel 80x20 "exit" [ quit ]
do [sl/data: 1 show sl ] ] ; end of layout
view center-face mwin
===Philippe
|
|
|
|
|
Logged
|
===Philippe
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2243 Posts in 587 Topics by 2010 Members
Latest Member: techpon
|