Skip to main content

DataStream<Data>

A very basic implementation of a data stream with backpressure support which does not use native JS streams or async iterators. This is handy for environments such as React Native which need polyfills for the above.

Extends

Type parameters

Type parameterValue
Data extends anyany

Constructors

new DataStream()

new DataStream<Data>(options?): DataStream<Data>

Parameters

ParameterType
options?DataStreamOptions

Returns

DataStream<Data>

Overrides

BaseObserver.constructor

Properties

PropertyType
dataQueueData[]

Accessors

closed

get closed(): boolean

Returns

boolean


highWatermark

get highWatermark(): number

Returns

number


lowWatermark

get lowWatermark(): number

Returns

number

Methods

close()

close(): Promise<void>

Returns

Promise<void>


enqueueData()

enqueueData(data): void

Enqueues data for the consumers to read

Parameters

ParameterType
dataData

Returns

void


forEach()

forEach(callback): () => void

Executes a callback for each data item in the stream

Parameters

ParameterType
callbackDataStreamCallback<Data>

Returns

Function

Returns

void


iterateAsyncListeners()

iterateAsyncListeners(cb): Promise<void>

Parameters

ParameterType
cb(listener) => Promise<any>

Returns

Promise<void>

Inherited from

BaseObserver.iterateAsyncListeners


iterateListeners()

iterateListeners(cb): void

Parameters

ParameterType
cb(listener) => any

Returns

void

Inherited from

BaseObserver.iterateListeners


map()

map<ReturnData>(callback): DataStream<ReturnData>

Creates a new data stream which is a map of the original

Type parameters

Type parameter
ReturnData

Parameters

ParameterType
callback(data) => ReturnData

Returns

DataStream<ReturnData>


read()

read(): Promise<null | Data>

Reads data once from the data stream

Returns

Promise<null | Data>

a Data payload or Null if the stream closed.


registerListener()

registerListener(listener): () => void

Register a listener for updates to the PowerSync client.

Parameters

ParameterType
listenerPartial<DataStreamListener<Data>>

Returns

Function

Returns

void

Inherited from

BaseObserver.registerListener