Documentation
¶
Overview ¶
Package pson implements experimental support for progressive JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal encodes a piece of data as JSON and writes it to out. This works almost exactly like json.Marshal except that it adds specialized support for AsyncFunc values. When one is encountered during the marshaling process, it is called concurrently. Once it returns and after the original object that it was encountered in has finished being marshaled, the value it returns is sent to out as well. This is performed recursively, allowing an AsyncFunc to return a value containing more AsyncFunc values which will in turn all be called in a similar way.
Every marshal, first for in and then for the results of the various AsyncFunc calls, will be written to out as a separate chunk. These will be obtained, written to, and then immediately closed. These calls do not happen concurrently with other chunks being written.
Every call to an AsyncFunc is passed a context dervived from the provided ctx but that is canceled when Marshal returns.
Marshal does not return until all AsyncFunc calls have fully exited or until one of them returns an error or an error is encountered during the encoding process.
Types ¶
type AsyncFunc ¶
An AsyncFunc represents a piece of data that should be sent later. See Marshal for more information.
type ChunkWriter ¶
type ChunkWriter interface {
Chunk() (io.WriteCloser, error)
}
ChunkWriter is something that can be written to in pieces. This is a way for Marshal to make sure that data is sent after each piece of JSON is ready. For simple use-cases, see Chunk.
func Chunk ¶
func Chunk(w io.Writer) ChunkWriter
Chunk returns a ChunkWriter that returns chunks that write directly to w and have no-op Close methods.