On Tue, Mar 24, 2020 at 4:03 PM David Storrs <[email protected]> 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?
```
(thread
(λ ()
(let loop ()
(match (sync/timeout timeout (udp-receive!-evt socket buffer))
[(list len shost sport)
;; do stuff
(loop)]
[#f
;; timed out; exit the loop and the thread
(void)]))))
```
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CAKfDxxzgwLVDH-YzNWnMkghy_bMXcMHsujhWAxqHH8U07drDYg%40mail.gmail.com.