racket/collects/2htdp/private/last.rkt
2010-11-06 10:19:24 -04:00

35 lines
703 B
Racket

#lang scheme/gui
(require "timer.ss")
(provide last-mixin)
(define last-mixin
(mixin (start-stop<%>) ()
;; to comunicate between stop! and last
(field [end:ch (make-channel)])
;; X -> Void
(define/override (stop! w)
(send-to-last w)
(super stop! w))
;; -> World
(define/public (last)
(define result (yield end:ch))
(if (exn? result) (raise result) result))
(field [dr:cust (current-custodian)])
;; X -> Void
;; send x to last method
(define/private (send-to-last x)
(parameterize ((current-custodian dr:cust))
(thread
(lambda ()
(channel-put end:ch x)))))
(super-new)))