Commits

Moritz Heidkamp  committed 05163db

close forked channels when their parent is closed

  • Participants
  • Parent commits 842dd98

Comments (0)

Files changed (2)

 (define (channel-fork! channel)
   (let ((mutex (channel-mutex channel)))
     (mutex-lock! mutex)
-    (let ((fork (apply make-channel (channel-messages channel))))
-      (push! (make-weak-locative fork) (channel-forks channel))
+    (let* ((fork  (apply make-channel (channel-messages channel)))
+           (fork* (make-weak-locative fork)))
+      (push! fork* (channel-forks channel))
       (mutex-unlock! mutex)
+      (on-channel-close
+       channel
+       (lambda ()
+         (and-let* ((fork (locative->object fork*)))
+           (channel-close! fork))))
       fork)))
 
 (define (on-channel-close channel thunk)

File tests/run.scm

   (test (r1) '(1 2 3))
   (test (r2) '(1 2 3 4))
 
+  (test-assert (not (channel-closed? c2)))
+  (channel-close! c1)
+  (test-assert (channel-closed? c2))
+
   (test-group "gc"
     (define c (make-channel))
     (define f (channel-fork! c))