Skip to content

Commit

Permalink
Use custodian for multi expressions check; fixes #609
Browse files Browse the repository at this point in the history
Ensure that the peeking port and thread are cleaned up using a
custodian. In practice this seems to matter only on Windows, for
reasons I don't understand.
  • Loading branch information
greghendershott committed Apr 5, 2022
1 parent e759312 commit 62c272e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions racket/interactions.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@
;;
;; - Use a thread + channel + sync/timeout so that, if the answer is
;; no because there is only a partial sexp -- e.g. "(+ 1" -- we
;; don't get stuck inside `read`.
;; don't get stuck inside `read`. Use a custodian to ensure that
;; the thread and peeking port are cleaned up; this seems to
;; matter on Windows wrt a break, as with issue #609.
(define ch (make-channel))
(thread
(λ ()
(channel-put ch
(with-handlers ([exn:fail? (λ _ #f)])
(define pin (peeking-input-port in))
(define v ((current-read-interaction) #f pin))
(not (eof-object? v))))))
(sync/timeout 0.01 ch))
(define cust (make-custodian))
(parameterize ([current-custodian cust])
(thread
(λ ()
(channel-put ch
(with-handlers ([values (λ _ #f)])
(define pin (peeking-input-port in))
(define v ((current-read-interaction) #f pin))
(not (eof-object? v)))))))
(begin0 (sync/timeout 0.01 ch)
(custodian-shutdown-all cust)))

(define (display-prompt str)
(fresh-line)
Expand Down

0 comments on commit 62c272e

Please sign in to comment.