Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Standardize a way for writable streams to do work after all data has been consumed #7348

@evansolomon

Description

@evansolomon

Transform streams can optionally have a _flush method that lets the stream do something after all incoming data has been consumed, but before the stream's readable side fires its 'end' event. It would be great if a similar convention existed for writable streams.

The particular use case I have in mind here is a writable stream that uploads data to S3 (source) that has to tell S3 that the upload is finished, then wait for a response. In our case, we chose to fire a 'close' event once that work is done. This is annoying for users though, because they have to know that special event exists. If they bind to the standard 'finish' event they may try to use the data produced by the writable stream before it's actually ready. Chaos ensues and tears are shed.

The two solutions I've thought about are (1) allowing writable streams to implement a _flush method or (2) indicating when the last data is being written so that the stream can delay calling the last callback until it's finished with it's post-processing work.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions