[REBOL] A couple of things regarding ports Re:(4)
From: petr:krenzelok:trz:cz at: 18-Sep-2000 12:25
[Al--Bri--xtra--co--nz] wrote:
> malte wrote:
> > Im also making a multi-connection app, and had the same problems, however,
> I don't get things to work with dispatch either..
> > perhaps Im not using it properly.. syntax, anyone? :)
> >
> > right now I go like
> > port: dispatch [port1 port2]
> >
> > wrong?
>
> Yes. That's wrong. Have a look at the source for 'dispatch:
>
> >> source dispatch
> dispatch: func [
> {Wait for a block of ports. As events happen, dispatch port handler
> blocks.}
> port-block [block!] {Block of port handler pairs (port can be timeout
> too).}
> /local ports awake timeblk result
> ][
> ports: copy []
> foreach [port job] port-block: reduce port-block [
> if any [number? port time? port] [if none? timeblk [timeblk: :job]]
> append ports port
> ]
> forever [
> either awake: wait/all ports [
> if foreach item awake [
> set/any 'result do select port-block item item
> if all [value? 'result 'break = :result] [break/return true]
> ] [break]
> ] [do :timeblk]
> ]
> ]
>
> Note the 'foreach:
> foreach [port job] port-block
ah, it's interesting - do you really prefer this aproach? (nested blocks) I
remember Carl ones discussed he prefers one aproach, but I don't remember the
result ...
I would probably prefer having separate block with handlers parallel to
port-block ...
-pekr-