From e30342236a3b9243dd670ad1921449d7f8456680 Mon Sep 17 00:00:00 2001 From: Noah W M <37620986+llNoahll@users.noreply.github.com> Date: Thu, 1 Aug 2019 20:40:23 +0800 Subject: [PATCH] guide: in example, display all strings in the result channel There may be still a string in the result-channel, because it is possible that the main thread exits before the result-thread calls `(channel-get result-channel)' and display its result. --- pkgs/racket-doc/scribblings/guide/concurrency.scrbl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/racket-doc/scribblings/guide/concurrency.scrbl b/pkgs/racket-doc/scribblings/guide/concurrency.scrbl index 8d0f713f7c..cab2cd2083 100644 --- a/pkgs/racket-doc/scribblings/guide/concurrency.scrbl +++ b/pkgs/racket-doc/scribblings/guide/concurrency.scrbl @@ -194,7 +194,7 @@ the items and then pass their results to the result thread via the @racket[resul (define result-thread (thread (lambda () (let loop () - (displayln (channel-get result-channel)) + (display (channel-get result-channel)) (loop))))) (define work-channel (make-channel)) @@ -206,10 +206,10 @@ the items and then pass their results to the result thread via the @racket[resul (case item [(DONE) (channel-put result-channel - (format "Thread ~a done" thread-id))] + (format "Thread ~a done\n" thread-id))] [else (channel-put result-channel - (format "Thread ~a processed ~a" + (format "Thread ~a processed ~a\n" thread-id item)) (loop)]))))) @@ -217,6 +217,7 @@ the items and then pass their results to the result thread via the @racket[resul (for ([item '(A B C D E F G H DONE DONE)]) (channel-put work-channel item)) (for-each thread-wait work-threads) +(channel-put result-channel "") (code:comment "waits until result-thread has printed all other output") ] @section{Buffered Asynchronous Channels}