On this page:
Plumber
Plumber.Flush  Handle
Plumber.current
Plumber.flush_  all
Plumber.add_  flush
Plumber.Flush  Handle.remove
0.45+9.2.0.3

16.2 Plumbers🔗ℹ

 import: rhombus/plumber open package: rhombus-lib

A plumber supports flush callbacks, which are normally triggered just before a Rhombus process exits. For example, a flush callback might flush an output port’s buffer.Flush callbacks are roughly analogous to the standard C library’s atexit, but flush callback can also be used in other, similar scenarios.

There is no guarantee that a flush callback will be called before a process terminates—either because the plumber is not the original plumber that is flushed on exit, or because the process is terminated forcibly (e.g., through a custodian shutdown).

class

class Plumber()

 

class

class Plumber.FlushHandle():

  constructor ~error

The Plumber class represents a plumber.

The Plumber.FlushHandle class represents a flush handle, which records a particular registration of a flush callback.

A context parameter that determines a current plumber for flush callbacks. For example, creating an output file [port] registers a flush callback with the current plumber to flush the port as long as the port is opened.

method

method (plumber :: Plumber).flush_all() :: Void

Calls all flush callbacks that are registered with plumber.

The flush callbacks to call are collected from plumber before the first one is called. If a flush callback registers a new flush callback, the new one is not called. If a flush callback raises an exception or otherwise escapes, then the remaining flush callbacks are not called.

method

method (plumber :: Plumber).add_flush(

  flush :: (Plumber.FlushHandle) -> ~any,

  ~weak: weak :: Any.to_boolean = #false

) :: Plumber.FlushHandle

Registers flush as a flush callback with plumber, so that flush is called for plumber.flush_all().

The result flush handle represents the registration of the callback, and it can be used with Plumber.FlushHandle.remove to unregister the callback.

The given flush is reachable from the flush handle, but if weak is true, then plumber retains only a weak reference to the result flush handle (and thus flush).

When flush is called as a flush callback, it is passed the same value that is returned by Plumber.add_flush so that flush can conveniently unregister itself. The call of flush is within a continuation barrier.

Unregisters the flush callback that was registered by the Plumber.add_flush call that produced fh.

If the registration represented by fh has been removed already, then Plumber.FlushHandle.remove has no effect.