Reputation: 2002
I'm writing a unit test and I want to:
Here's the code I tried:
#lang racket/base
(require plot racket/class)
(define f
(plot3d-frame (surface3d (λ (x y) (* (cos x) (sin y))) -3.0 3.0 -3.0 3.0)))
(send f show #true)
(sleep 10)
(send f show #false)
Running this opens a blank frame, waits 10 seconds, and closes the frame. The plot never appears. I guess this is because sleep
puts the whole thread, including the eventspace, to sleep.
Is there a way to make my code sleep without making the GUI to sleep?
Upvotes: 1
Views: 518
Reputation: 2002
Yes, use sleep/yield
#lang racket/base
(require plot racket/class racket/gui/base)
(define f
(plot3d-frame (surface3d (λ (x y) (* (cos x) (sin y))) -3.0 3.0 -3.0 3.0)))
(send f show #true)
(sleep/yield 10)
(send f show #false)
;; "It works every time!"
Upvotes: 1