File: async

package info (click to toggle)
newlisp 10.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 6,248 kB
  • sloc: ansic: 33,280; lisp: 4,181; sh: 609; makefile: 215
file content (23 lines) | stat: -rwxr-xr-x 508 bytes parent folder | download | duplicates (3)
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)