Merge unstable/future with racket/future.

This commit is contained in:
Vincent St-Amour 2015-07-22 11:21:39 -05:00
parent ef716ed15d
commit 91c422bb66
2 changed files with 33 additions and 2 deletions

View File

@ -126,6 +126,16 @@ execute through a call to @racket[touch], however.
}
@deftogether[[
@defform[(for/async (for-clause ...) body ...+)]
@defform[(for*/async (for-clause ...) body ...+)]]]{
Like @racket[for] and @racket[for*], but each iteration of the
@racket[body] is executed in a separate @racket[future], and
the futures may be @racket[touch]ed in any order.
}
@; ----------------------------------------
@section{Future Semaphores}

View File

@ -1,5 +1,6 @@
#lang racket/base
(require '#%futures)
(require '#%futures
(for-syntax racket/base))
(provide future?
future
@ -13,4 +14,24 @@
fsemaphore-wait
fsemaphore-try-wait?
would-be-future
futures-enabled?)
futures-enabled?
for/async
for*/async)
;; Note: order of touches not guaranteed.
(define-syntaxes (for/async for*/async)
(let ()
(define ((transformer for/fold/derived-id) stx)
(syntax-case stx ()
[(_ (clause ...) . body)
(quasisyntax/loc stx
(let ([futures
(#,for/fold/derived-id #,stx ([fs null]) (clause ...)
(cons (future (lambda () . body)) fs))])
;; touches futures in original order
(let loop ([fs futures])
(cond [(pair? fs) (begin (loop (cdr fs)) (touch (car fs)))]
[else (void)]))))]))
(values (transformer #'for/fold/derived)
(transformer #'for*/fold/derived))))