From 334f36b0d0da70a4efb8239390254e69f941c3ef Mon Sep 17 00:00:00 2001 From: "amano.kenji" Date: Fri, 16 Feb 2024 00:19:20 +0000 Subject: [PATCH] Ignore channel errors in spork/stream/lines-channel because they are closed by users. Thus, they are not interesting. Stream errors can occur outside user control, and users may want to investigate stream errors with supervisors. --- spork/stream.janet | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spork/stream.janet b/spork/stream.janet index a60a100..c70113e 100644 --- a/spork/stream.janet +++ b/spork/stream.janet @@ -34,7 +34,7 @@ from the channel, or close the stream and the channel. Otherwise, the task remains frozen in the background. After the channel gives the last line, the channel is closed. After stream or channel is closed, the channel gives `nil`. If `supervisor` is a channel, the channel is used as the supervisor channel. If `supervisor` is nil or not specified, the - task inherits the current supervisor channel. + task inherits the current supervisor channel. The supervisor channel will be given stream errors. ``` [stream &named separator supervisor] (def fiber (lines stream :separator separator)) @@ -42,7 +42,10 @@ (defn give-lines [] (when-let [line (resume fiber)] - (ev/give ch line) + (try + (ev/give ch line) + # If channel is already closed, don't throw an error because channel errors are not interesting. + ([_])) (give-lines))) (ev/go |(defer (:close ch) (give-lines))