Commits

Moritz Heidkamp committed 5aa12c1

implement channel-receiver-remove!

Comments (0)

Files changed (2)

  channel-enqueue! channel-receive!
  on-channel-receive on-channel-close on-channel-drain
  channel-messages channel-empty?
+ channel-receiver-remove!
  channel-close! channel-closed? channel-drained?
  channel-forks make-receiving-channel
  channel-fork! channel-fold! channel-map! channel-filter!)
 
 (import chicken scheme)
-(use data-structures srfi-18 
+(use data-structures srfi-18 srfi-1
      (only srfi-1 filter)
      (only miscmacros push!)
      (only lolevel make-weak-locative locative->object))
     (mutex-unlock! mutex)
     (channel-flush! channel)))
 
+(define (channel-receiver-remove! channel receiver)
+  (let ((mutex (channel-mutex channel)))
+    (mutex-lock! mutex)
+    (set! (channel-receivers channel)
+          (remove (lambda (r) (eq? r receiver))
+                  (channel-receivers channel)))
+    (mutex-unlock! mutex)))
+
 (define (channel-receive! channel . procs)
   (let ((mutex   (channel-mutex channel))
         (queue   (channel-queue channel))
   (channel-enqueue! c 5)
   (test (results-1) '(1 2 3 4 5))
   (test (results-2) '(4 4))
-  (test (results-3) '(5)))
+  (test (results-3) '(5))
+  (channel-receiver-remove! c results-1)
+  (channel-enqueue! c 6)
+  (test (results-1) '(1 2 3 4 5))
+  (test (results-3) '(5 6)))
 
 (test-group "parallel channel receivers"