adjusted the test system to use just one browser window instance instead of several, but I'm still running into the browser crash. Ugh.

This commit is contained in:
Danny Yoo 2011-06-06 11:34:01 -04:00
parent c92f018aa8
commit bd2487a051

View File

@ -25,30 +25,13 @@
;; make-evaluate: (Any output-port) -> void
;; Produce a JavaScript evaluator that cooperates with a browser.
;; The JavaScript-compiler is expected to write out a thunk. When invoked,
;; the thunk should return a function that consumes three values, corresponding
;; to success, failure, and other parameters to evaluation. For example:
;;
;; (make-evaluate (lambda (program op)
;; (fprintf op "(function() {
;; return function(success, fail, params) {
;; success('ok');
;; }})")))
;;
;; is a do-nothing evaluator that will always give back 'ok'.
;;
;; At the moment, the evaluator will pass in a parameter that binds 'currentDisplayer' to a function
;; that captures output.
(define (make-evaluate javascript-compiler)
(define ch
(let ()
(define port (+ 8000 (random 8000)))
;; This channel's meant to serialize use of the web server.
(define ch (make-channel))
;; start up the web server
;; The web server responds to two types of requests
;; ?comet Starting up the comet request path.
@ -60,7 +43,7 @@
(cond
;; Server-side sync for a program
[(exists-binding? 'comet (request-bindings req))
(handle-comet req)]
(handle-comet ch req)]
;; Normal result came back
[(exists-binding? 'v (request-bindings req))
@ -82,12 +65,18 @@
#:servlet-path "/eval"))))
ch))
(define *alarm-timeout* 30000)
(define (handle-comet req)
(define (handle-comet ch req)
(let/ec return
(let* ([alarm (alarm-evt (+ (current-inexact-milliseconds) *alarm-timeout*))]
[program (sync ch alarm)]
[javascript-compiler+program (sync ch alarm)]
[javascript-compiler (first javascript-compiler+program)]
[program (second javascript-compiler+program)]
[op (open-output-bytes)])
(cond
[(eq? program alarm)
@ -120,6 +109,10 @@ EOF
(list #"" (get-output-bytes op)))]))))
(define (try-again-response)
(response/full 200 #"Try again"
(current-seconds)
@ -387,17 +380,37 @@ EOF
;; make-evaluate: (Any output-port) -> (sexp -> (values string number))
;; Produce a JavaScript evaluator that cooperates with a browser.
;; The JavaScript-compiler is expected to write out a thunk. When invoked,
;; the thunk should return a function that consumes three values, corresponding
;; to success, failure, and other parameters to evaluation. For example:
;;
;; (make-evaluate (lambda (program op)
;; (fprintf op "(function() {
;; return function(success, fail, params) {
;; success('ok');
;; }})")))
;;
;; is a do-nothing evaluator that will always give back 'ok'.
;;
;; At the moment, the evaluator will pass in a parameter that binds 'currentDisplayer' to a function
;; that captures output.
(define (make-evaluate javascript-compiler)
;; evaluate: sexp -> (values string number)
;; A little driver to test the evalution of expressions, using a browser to help.
;; Returns the captured result of stdout, plus # of milliseconds it took to execute.
(define (evaluate e)
;; Send the program to the web browser, and wait for the thread to send back
(channel-put ch e)
(channel-put ch (list javascript-compiler e))
(let ([result (channel-get ch)])
(cond [(error-happened? result)
(raise result)]
[else
result])))
evaluate)