On Tue, Mar 24, 2020 at 4:03 PM David Storrs <david.sto...@gmail.com> wrote:
> I've got this code:
> (thread
>   (thunk
>     (let loop ()
>       (define-values (len shost sport) (udp-receive! socket buffer))
>       ...do stuff with the received message...
>      (loop))))
> I'd like to be able to say "If you haven't received a message in X time, kill 
> the thread".  I'm not sure how to enact that; sync/timeout won't do it since 
> the thread won't return.  I've thought of weird signaling systems using 
> channels or set! on some external value or etc, but they are all terrible.
> What's the right way to do this?

Not quite sure what you mean when you say "sync/timeout won't do it
since the thread won't return." You'll know when you timed-out, so you
can return in that case. Wouldn't something like this work?

 (λ ()
   (let loop ()
     (match (sync/timeout timeout (udp-receive!-evt socket buffer))
       [(list len shost sport)
        ;; do stuff
        ;; timed out; exit the loop and the thread

Apologies if I've misunderstood you.

- Jon

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 

Reply via email to