How to flush-output through make-output-port?

I have made a wrapper around some port via

(define my-port (make-output-port
     'my-port
     ; This port is ready when the original is ready:
     inner-port
     ; Writing procedure:
     (lambda (s start end non-block? breakable?)
        ...) ...))

But if I call (flush-output my-port) it doesn't flush data on inner-port. Is it possible to catch flush-output call and flush wrapped port?

A call to (flush-output my-port) causes a call to your writing procedure with a zero-length buffer region. See the docs for make-output-port, the paragraph starting "If the start and end indices are the same..." You must detect that case and handle it to implement flushing.

1 Like