Skip to content

Commit

Permalink
Ignore channel errors in spork/stream/lines-channel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amano-kenji committed Feb 16, 2024
1 parent 21298e0 commit 334f36b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions spork/stream.janet
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
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))
(def ch (ev/chan))
(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))
Expand Down

0 comments on commit 334f36b

Please sign in to comment.