1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#!/usr/bin/env newlisp
; demo use spawn and sync for
; aysnchronous HTTP get-url requests
(set 'start (time-of-day))
; callback routine when page is finished
(define (page-ready pid)
(println "pid:" pid)
(println "received: " (length page) " bytes"))
; start fetching page, will return immediately
(spawn 'page (get-url "http://www.yahoo.com"))
; specify call back, wait and do something else
(until (true? (sync 100 page-ready) )
(println (- (time-of-day) start) " ms"))
; all done
(exit)
|