chickadee » sdl2 » wait-event-timeout!

wait-event! #!optional result-event delay-fnprocedure
wait-event-timeout! timeout #!optional result-event delay-fnprocedure

Wait for the next event to appear on the event queue, then return it. The returned event will be removed from the event queue. If there is already an event on the event queue, it will be returned immediately. Otherwise, these procedures will block the current thread until the next event appears (or the timeout expires).

  • wait-event! will wait indefinitely for an event to appear.
  • wait-event-timeout! will stop waiting and return #f if no event appears within timeout milliseconds. (It may actually wait a few milliseconds longer than specified. You should not rely on its timing being very precise.)

If result-event is omitted or #f, a new managed sdl2:event will be returned. If result-event is an sdl2:event, it will be modified and returned. This allows you to allocate a single event and reuse it many times in your event loop, so that your program does not create as much garbage for the garbage collector.

delay-fn must be a procedure which accepts a number of milliseconds to sleep. By default it is the delay! procedure from this egg. If you are using SRFI-18 multithreading, you should provide a compatible delay procedure instead:

(import srfi-18)
(define (thread-delay! ms) (thread-sleep! (* ms 0.001)))
(sdl2:wait-event! (sdl2:make-event) thread-delay!)

These procedures are inspired by (but do not actually use) SDL_WaitEvent and SDL_WaitEventTimeout.