Skip to main content

OnSegmentSealed

type OnSegmentSealed = (segment) => boolean;

Called when a segment is sealed, i.e. when it is full and no more lines will ever be written to it, and when TextRingBuffer.flush is called. This is the extension seam for persisting evicted logs, e.g. to IndexedDB.

The buffer is in a consistent state during the call, so the callee is free to write to it, e.g. to report that persisting failed. Such lines are appended to the segment which is now active, and never to the sealed one. Errors thrown by the callee are caught and ignored, so that failing to persist a segment cannot break the write which sealed it. The hook is not re-entrant: segments sealed by writes made from within it are not reported.

Parameters​

ParameterTypeDescription
segmentSealedTextSegmentThe sealed segment

Returns​

boolean

true when the callee takes ownership of the segment's memory, in which case the buffer forgets the segment (its lines are no longer readable in-memory) and allocates a replacement. Return false to let the buffer keep the segment in memory and recycle it once capacity is needed.