summaryrefslogtreecommitdiffstats
path: root/tests/018/close-delegate.tl
blob: 4cf1d6505b963685414d54d2eb83ddd10511eeaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(load "../common")

(defstruct refcount-close stream-wrap
  stream
  (count 1)

  (:method close (me throw-on-error-p)
    (put-line `close called, count @{me.count}`)
    (when (plusp me.count)
      (if (zerop (dec me.count))
        (close-stream me.stream throw-on-error-p)))))

(flow
  (with-stream (s (make-struct-delegate-stream
                    (new refcount-close
                         count 2
                         stream (open-file *load-path*))))
    (get-lines s))
  len
  prinl)