diff --git a/collects/unstable/future.rkt b/collects/unstable/future.rkt new file mode 100644 index 0000000000..be2dd58e40 --- /dev/null +++ b/collects/unstable/future.rkt @@ -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)))) diff --git a/collects/unstable/gui/blur.rkt b/collects/unstable/gui/blur.rkt index bed3b32f71..c754af5c65 100644 --- a/collects/unstable/gui/blur.rkt +++ b/collects/unstable/gui/blur.rkt @@ -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]) diff --git a/collects/unstable/scribblings/future.scrbl b/collects/unstable/scribblings/future.scrbl new file mode 100644 index 0000000000..e9bb6f2e38 --- /dev/null +++ b/collects/unstable/scribblings/future.scrbl @@ -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. +} diff --git a/collects/unstable/scribblings/unstable.scrbl b/collects/unstable/scribblings/unstable.scrbl index 80d58556fb..3c72f03fbf 100644 --- a/collects/unstable/scribblings/unstable.scrbl +++ b/collects/unstable/scribblings/unstable.scrbl @@ -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"]