;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2010-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

#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))
