added unstable/future
This commit is contained in:
parent
bb5bcf2ae1
commit
61ab93b87e
23
collects/unstable/future.rkt
Normal file
23
collects/unstable/future.rkt
Normal file
|
@ -0,0 +1,23 @@
|
|||
#lang racket/base
|
||||
(require racket/future
|
||||
(for-syntax racket/base))
|
||||
(provide 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))))
|
|
@ -6,7 +6,7 @@
|
|||
racket/draw
|
||||
racket/pretty
|
||||
racket/math
|
||||
racket/future
|
||||
unstable/future
|
||||
slideshow/pict)
|
||||
|
||||
;; TODO: use clipping regions to avoid computing unused pixels
|
||||
|
@ -29,14 +29,6 @@
|
|||
(exact-nonnegative-integer?)
|
||||
void?)])
|
||||
|
||||
(define-syntax (for/async stx)
|
||||
(syntax-case stx ()
|
||||
[(_ (clause ...) . body)
|
||||
#`(let ([fs
|
||||
(for/fold/derived #,stx ([fs null]) (clause ...)
|
||||
(cons (future (lambda () . body)) fs))])
|
||||
(for-each touch fs))]))
|
||||
|
||||
;; ----
|
||||
|
||||
(define (blur p hbr [vbr hbr] #:auto-inset? [auto-inset? #f])
|
||||
|
|
19
collects/unstable/scribblings/future.scrbl
Normal file
19
collects/unstable/scribblings/future.scrbl
Normal file
|
@ -0,0 +1,19 @@
|
|||
#lang scribble/manual
|
||||
@(require "utils.rkt"
|
||||
(for-label racket/base
|
||||
racket/future
|
||||
unstable/future))
|
||||
|
||||
@title[#:tag "future"]{Futures}
|
||||
@unstable[@author+email["Ryan Culpepper" "ryanc@racket-lang.org"]]
|
||||
|
||||
@defmodule[unstable/future]
|
||||
|
||||
@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.
|
||||
}
|
|
@ -82,6 +82,7 @@ Keep documentation and tests up to date.
|
|||
@include-section["exn.scrbl"]
|
||||
@include-section["file.scrbl"]
|
||||
@include-section["find.scrbl"]
|
||||
@include-section["future.scrbl"]
|
||||
@include-section["mutated-vars.scrbl"] ;; Finding Mutable Variables
|
||||
@include-section["function.scrbl"]
|
||||
@include-section["generics.scrbl"]
|
||||
|
|
Loading…
Reference in New Issue
Block a user