Class ydn.db.Streamer

An Streamer class retrieve predefined reference value of given primary keys. The streamer instance run out of main transaction queue and execute to retrieve the value of given key immediately. Streamer areoptimized for fetching linearly predictable stream of keys and may be pre-cached by the library or underlining storage mechanisms.

ydn.db.Streamer(db, store_name)
Create a streamer of a store.

The following example illustrate creating user streamer.

var streamer = new ydn.db.Streamer(db, 'user');
streamer.setSink(function(a_user) {
streamer.push('a'); // log user 'a'
streamer.push('b'); // log user 'b'
{!ydn.db.Storage} db
The storage.
{string} store_name
The store name.

ydn.db.Streamer(db, store_name, field_name)
Create a projection streamer.

The following example illustrate creating key streamer of projection field 'name' of store 'user'.

var streamer = new ydn.db.Streamer(db, 'user', 'name');
streamer.setSink(function(name) {
streamer.push('a'); // log name of user 'a'
streamer.push('b'); // log name of user 'b'
{!ydn.db.Storage} db
The storage.
{string} store_name
The store name.
{string} field_name
The projection field name.

Collect all values in the stack.

Collect all values in the stack and empty the stack. This method wait all pending keys are collected.

This method is generally invoke at the end of an operation to ensure all values are collected. This is also use if no sink function is set.

{!function(keys: !Array, values: !Array)} callback
The callback to receive values as an array.

Push a key to retrieve its value.
{InvalidOperationException} If collection process is running.

setRelation(store_name, field_name)
Set a foreign key relationship.

This attribute indicate how this key should be obtained from.

{string} store_name
The other store name.
{string=} field_name
Foreign key field name. If not provided, the primary key is assumed.

Set a sink function to receive streaming values.

The value is clear from the stack after a value is pop to the sink function.

{function(key: *, value: *, onCompleted: Function?): (boolean|undefined)} pop_function
The pop function to receive streaming value. On complete callback function is null if no pending value in the streamer. If on complete callback function is present, return true to wait for the callback.