#lang syndicate

(provide make-buffer)

(define (make-buffer)
  (field [pending '()])
  (define (push item)
    (pending (cons item (pending))))
  (define (drain handler)
    (begin/dataflow
      (when (pair? (pending))
        (for [(item (in-list (reverse (pending))))] (handler item))
        (pending '()))))
  (values push drain))
