> On Jun 15, 2019, at 8:31 AM, Robby Findler <ro...@cs.northwestern.edu> wrote: > > A standard way to work with this is to send a channel over in the > first communication and then the communication that's specific to that > initial request happens on that channel.
This is probably the crudest possible implementation of your suggestion, but this version avoids mismatched requests & responses. The `loopback-p` makes a table of the worker channels at the outset. After that, as it gets requests, it dispatches the response directly to the worker that issued the request. (I'm not asking you to review this code, I'm just posting this for curious people of the future.) #lang racket (require racket/place) (provide main) (define (main) (define loopback-p (place ch (let ([chs (make-hasheq)]) (let loop () (match (place-channel-get ch) [(list wpidx (? place-channel? wp)) (hash-set! chs wpidx wp) (place-channel-put wp 'ack)] [(list wpidx count) (place-channel-put (hash-ref chs wpidx) (list wpidx count))]) (loop))))) (define worker-ps (for/list ([i (in-range (processor-count))]) (place ch (match-define (list loopback-p wpidx wp) (place-channel-get ch)) (place-channel-put loopback-p (list wpidx wp)) (place-channel-get ch) ; wait for 'ack (let make-request ([count 1]) (place-channel-put loopback-p (list wpidx count)) (match-define (list wpidxout countout) (place-channel-get ch)) (displayln (format "worker request ~a:~a got response ~a:~a ~a" wpidx count wpidxout countout (if (and (eq? wpidx wpidxout) (eq? count countout)) "" "### fail"))) (sleep (* 0.01 (add1 wpidx))) ; multiplier makes workers go at different speeds (make-request (add1 count)))))) (for ([(wp wpidx) (in-indexed worker-ps)]) (place-channel-put wp (list loopback-p wpidx wp))) (map place-wait worker-ps)) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/14FF4C4B-CE93-4B10-B496-B678DA74B4F4%40mbtype.com. For more options, visit https://groups.google.com/d/optout.