All pastes #2108089 Raw Edit

Someone

public text v1 · immutable
#2108089 ·published 2012-01-31 11:03 UTC
rendered paste body
(use util.queue)
(use control.thread-pool)
(use gauche.parameter)
(use srfi-27)
(use rfc.http)

(define *max-thread* (make-parameter 3))

(define (threaded-map proc lst)
  (let1 pool (make-thread-pool (*max-thread*))
    (for-each (^x (add-job! pool (cut proc x) #t)) lst)
    (terminate-all! pool)
    (map (cut ~ <> 'result) (queue->list (thread-pool-results pool)))
    ))

(define a
  (threaded-map
   (^x
    (sys-sleep (random-integer 4))
    (http-get "example.com" "/")
    x)
   '(1 2 3 4 5 6 7 8)))

(display a)